From 7c6be94630d35793e58fafd38625c29779f7a09a Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sun, 11 Mar 2018 08:36:02 +0100 Subject: [PATCH] [cli] Restore the --help option behavior Fixes #381 --- gitlab/cli.py | 12 +++++++++--- gitlab/v4/cli.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gitlab/cli.py b/gitlab/cli.py index 36a1bdadb..91a7dde55 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -77,8 +77,8 @@ def cls_to_what(cls): return camel_re.sub(r'\1-\2', cls.__name__).lower() -def _get_base_parser(): - parser = argparse.ArgumentParser( +def _get_base_parser(add_help=True): + parser = argparse.ArgumentParser(add_help=add_help, description="GitLab API Command Line Interface") parser.add_argument("--version", help="Display the version.", action="store_true") @@ -132,14 +132,20 @@ def main(): print(gitlab.__version__) exit(0) - parser = _get_base_parser() + parser = _get_base_parser(add_help=False) + # 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 (options, args) = parser.parse_known_args(sys.argv) config = gitlab.config.GitlabConfigParser(options.gitlab, options.config_file) 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 parser = _get_parser(cli_module) args = parser.parse_args(sys.argv[1:]) + config_files = args.config_file gitlab_id = args.gitlab verbose = args.verbose diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index cd513f003..e6f335115 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -240,7 +240,7 @@ def extend_parser(parser): arg_name = cli.cls_to_what(cls) object_group = subparsers.add_parser(arg_name) - object_subparsers = object_group.add_subparsers( + object_subparsers = object_group.add_subparsers(title='action', dest='action', help="Action to execute.") _populate_sub_parser_by_class(cls, object_subparsers) object_subparsers.required = True