From 6bb4d17a92832701b9f064a6577488cc42d20645 Mon Sep 17 00:00:00 2001 From: Max Wittig Date: Tue, 2 Oct 2018 19:56:53 +0200 Subject: fix(cli): print help and usage without config file Fixes #560 --- gitlab/cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gitlab/cli.py') diff --git a/gitlab/cli.py b/gitlab/cli.py index 4870192..e79ac6d 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -98,7 +98,7 @@ def _get_base_parser(add_help=True): "will be used."), required=False) parser.add_argument("-o", "--output", - help=("Output format (v4 only): json|legacy|yaml"), + help="Output format (v4 only): json|legacy|yaml", required=False, choices=['json', 'legacy', 'yaml'], default="legacy") @@ -135,6 +135,10 @@ def main(): exit(0) parser = _get_base_parser(add_help=False) + if "--help" in sys.argv or "-h" in sys.argv: + parser.print_help() + exit(0) + # This first parsing step is used to find the gitlab config to use, and # load the propermodule (v3 or v4) accordingly. At that point we don't have # any subparser setup -- cgit v1.2.1 From 6ad9da04496f040ae7d95701422434bc935a5a80 Mon Sep 17 00:00:00 2001 From: Max Wittig Date: Sun, 4 Nov 2018 16:52:32 +0100 Subject: fix(cli): exit on config parse error, instead of crashing * Exit and hint user about possible errors * test: adjust test cases to config missing error --- gitlab/cli.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'gitlab/cli.py') diff --git a/gitlab/cli.py b/gitlab/cli.py index e79ac6d..17917f5 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -17,6 +17,7 @@ # along with this program. If not, see . from __future__ import print_function + import argparse import functools import importlib @@ -143,9 +144,13 @@ def main(): # load the propermodule (v3 or v4) accordingly. At that point we don't have # any subparser setup (options, args) = parser.parse_known_args(sys.argv) - - config = gitlab.config.GitlabConfigParser(options.gitlab, - options.config_file) + try: + config = gitlab.config.GitlabConfigParser( + options.gitlab, + options.config_file + ) + except gitlab.config.ConfigError as e: + sys.exit(e) cli_module = importlib.import_module('gitlab.v%s.cli' % config.api_version) # Now we build the entire set of subcommands and do the complete parsing -- cgit v1.2.1