Skip to content

Commit

Permalink
[cli] Restore the --help option behavior
Browse files Browse the repository at this point in the history
Fixes #381
  • Loading branch information
Gauvain Pocentek committed Mar 11, 2018
1 parent d35a31d commit 7c6be94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions gitlab/cli.py
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gitlab/v4/cli.py
Expand Up @@ -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
Expand Down

0 comments on commit 7c6be94

Please sign in to comment.