diff options
author | Gauvain Pocentek <gauvain.pocentek@objectif-libre.com> | 2015-05-13 20:20:55 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain.pocentek@objectif-libre.com> | 2015-05-13 20:20:55 +0200 |
commit | 711c5be6f8210a40de056ba5359d61f877d925c8 (patch) | |
tree | 8149e1cbe81d2a81b232dbd9e4c05160cef37027 /gitlab/cli.py | |
parent | bed3adf688cf2061bb684d285c92a27eec6124af (diff) | |
download | gitlab-711c5be6f8210a40de056ba5359d61f877d925c8.tar.gz |
CLI: provide a --config-file option
Diffstat (limited to 'gitlab/cli.py')
-rwxr-xr-x | gitlab/cli.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py index 1805cde..fcbecd8 100755 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -232,12 +232,14 @@ def main(): parser = argparse.ArgumentParser( description="GitLab API Command Line Interface") parser.add_argument("-v", "--verbose", "--fancy", - help="increase output verbosity", + help="Verbose mode", action="store_true") + parser.add_argument("-c", "--config-file", action='append', + help=("Configuration file to use. Can be used " + "multiple times.")) parser.add_argument("--gitlab", - help=("Specifies which python-gitlab.cfg " - "configuration section should be used. " - "If not defined, the default selection " + help=("Which configuration section should " + "be used. If not defined, the default selection " "will be used."), required=False) @@ -263,10 +265,17 @@ def main(): arg = parser.parse_args() args = arg.__dict__ + files = arg.config_file or ['/etc/python-gitlab.cfg', + os.path.expanduser('~/.python-gitlab.cfg')] # read the config config = configparser.ConfigParser() - config.read(['/etc/python-gitlab.cfg', - os.path.expanduser('~/.python-gitlab.cfg')]) + try: + config.read(files) + except Exception as e: + print("Impossible to parse the configuration file(s): %s" % + str(e)) + sys.exit(1) + gitlab_id = arg.gitlab # conflicts with "gitlab" attribute from GitlabObject class args.pop("gitlab") |