Skip to content

Commit

Permalink
Add multi account support
Browse files Browse the repository at this point in the history
  • Loading branch information
egegunes committed Jun 19, 2019
1 parent 08169ac commit 6c02b9e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions redmine/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class Config:
def __init__(self, *args, **kwargs):
def __init__(self, account=None):
HOME = os.getenv("HOME")
self.paths = [
os.path.join(HOME, ".redmine.conf"),
Expand All @@ -15,6 +15,7 @@ def __init__(self, *args, **kwargs):
self.url = None
self.api_key = None
self.aliases = {}
self.account = account

URL = os.getenv("REDMINE_URL")
API_KEY = os.getenv("REDMINE_API_KEY")
Expand All @@ -32,9 +33,12 @@ def read_from_file(self):
config.read(path)
break

self.url = config["redmine"]["url"]
self.api_key = config["redmine"]["key"]
self.ssl_verify = config["redmine"].getboolean("ssl_verify")
if self.account is None:
self.account = config["accounts"]["default"]

self.url = config[self.account]["url"]
self.api_key = config[self.account]["key"]
self.ssl_verify = config[self.account].getboolean("ssl_verify")

try:
self.aliases.update(config.items("aliases"))
Expand Down
7 changes: 4 additions & 3 deletions redmine/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from requests.exceptions import HTTPError

from redmine.cli.alias import AliasedGroup
from redmine.cli.config import pass_config
from redmine.cli.config import Config, pass_config
from redmine.cli.helpers import get_description, get_note
from redmine.cli.options import OPTIONS
from redmine.issue import Issue, IssueStatus
Expand All @@ -27,9 +27,10 @@
show_default=True,
default=False,
)
@pass_config
@click.option(OPTIONS["account"]["long"])
@click.pass_context
def cli(ctx, cfg, **kwargs):
def cli(ctx, **kwargs):
cfg = Config(kwargs.get("account"))
redmine = Redmine(
cfg.url, cfg.api_key, cfg.ssl_verify, invalidate_cache=kwargs.get("force")
)
Expand Down
1 change: 1 addition & 0 deletions redmine/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
"edit": {"long": "--edit/--no-edit", "short": "-e/-E"},
"force": {"long": "--force/--no-force", "help": "Invalidate cache"},
"json": {"long": "--json/--no-json"},
"account": {"long": "--account"},
}

0 comments on commit 6c02b9e

Please sign in to comment.