Skip to content

Commit 7c6be94

Browse files
author
Gauvain Pocentek
committed
[cli] Restore the --help option behavior
Fixes #381
1 parent d35a31d commit 7c6be94

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

gitlab/cli.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def cls_to_what(cls):
7777
return camel_re.sub(r'\1-\2', cls.__name__).lower()
7878

7979

80-
def _get_base_parser():
81-
parser = argparse.ArgumentParser(
80+
def _get_base_parser(add_help=True):
81+
parser = argparse.ArgumentParser(add_help=add_help,
8282
description="GitLab API Command Line Interface")
8383
parser.add_argument("--version", help="Display the version.",
8484
action="store_true")
@@ -132,14 +132,20 @@ def main():
132132
print(gitlab.__version__)
133133
exit(0)
134134

135-
parser = _get_base_parser()
135+
parser = _get_base_parser(add_help=False)
136+
# This first parsing step is used to find the gitlab config to use, and
137+
# load the propermodule (v3 or v4) accordingly. At that point we don't have
138+
# any subparser setup
136139
(options, args) = parser.parse_known_args(sys.argv)
137140

138141
config = gitlab.config.GitlabConfigParser(options.gitlab,
139142
options.config_file)
140143
cli_module = importlib.import_module('gitlab.v%s.cli' % config.api_version)
144+
145+
# Now we build the entire set of subcommands and do the complete parsing
141146
parser = _get_parser(cli_module)
142147
args = parser.parse_args(sys.argv[1:])
148+
143149
config_files = args.config_file
144150
gitlab_id = args.gitlab
145151
verbose = args.verbose

gitlab/v4/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def extend_parser(parser):
240240
arg_name = cli.cls_to_what(cls)
241241
object_group = subparsers.add_parser(arg_name)
242242

243-
object_subparsers = object_group.add_subparsers(
243+
object_subparsers = object_group.add_subparsers(title='action',
244244
dest='action', help="Action to execute.")
245245
_populate_sub_parser_by_class(cls, object_subparsers)
246246
object_subparsers.required = True

0 commit comments

Comments
 (0)