8000 CLI: provide a --config-file option · python-gitlab/python-gitlab@711c5be · GitHub
[go: up one dir, main page]

Skip to content

Commit 711c5be

Browse files
author
Gauvain Pocentek
committed
CLI: provide a --config-file option
1 parent bed3adf commit 711c5be

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

gitlab/cli.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,14 @@ def main():
232232
parser = argparse.ArgumentParser(
233233
description="GitLab API Command Line Interface")
234234
parser.add_argument("-v", "--verbose", "--fancy",
235-
help="increase output verbosity",
235+
help="Verbose mode",
236236
action="store_true")
237+
parser.add_argument("-c", "--config-file", action='append',
238+
help=("Configuration file to use. Can be used "
239+
"multiple times."))
237240
parser.add_argument("--gitlab",
238-
help=("Specifies which python-gitlab.cfg "
239-
"configuration section should be used. "
240-
"If not defined, the default selection "
241+
help=("Which configuration section should "
242+
"be used. If not defined, the default selection "
241243
"will be used."),
242244
required=False)
243245

@@ -263,10 +265,17 @@ def main():
263265
arg = parser.parse_args()
264266
args = arg.__dict__
265267

268+
files = arg.config_file or ['/etc/python-gitlab.cfg',
269+
os.path.expanduser('~/.python-gitlab.cfg')]
266270
# read the config
267271
config = configparser.ConfigParser()
268-
config.read(['/etc/python-gitlab.cfg',
269-
os.path.expanduser('~/.python-gitlab.cfg')])
272+
try:
273+
config.read(files)
274+
except Exception as e:
275+
print("Impossible to parse the configuration file(s): %s" %
276+
str(e))
277+
sys.exit(1)
278+
270279
gitlab_id = arg.gitlab
271280
# conflicts with "gitlab" attribute from GitlabObject class
272281
args.pop("gitlab")

0 commit comments

Comments
 (0)
0