diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2016-11-19 12:24:53 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2016-11-19 12:24:53 +0100 |
commit | f5f734e3a714693c9596a9f57bcb94deb8c9813e (patch) | |
tree | edd8345ca424c2d0faa482515fb8ec7452e177a5 /gitlab/cli.py | |
parent | e64d0b997776387f400eaec21c37ce6e58d49095 (diff) | |
download | gitlab-f5f734e3a714693c9596a9f57bcb94deb8c9813e.tar.gz |
CLI: add support for project all --all
Rework the extra opts definition to allow setting typed arguments.
Fixes #153
Diffstat (limited to 'gitlab/cli.py')
-rw-r--r-- | gitlab/cli.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py index 1826a7b..ec4274d 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -58,7 +58,7 @@ EXTRA_ACTIONS = { gitlab.ProjectMilestone: {'issues': {'required': ['id', 'project-id']}}, gitlab.Project: {'search': {'required': ['query']}, 'owned': {}, - 'all': {}, + 'all': {'optional': [('all', bool)]}, 'starred': {}, 'star': {'required': ['id']}, 'unstar': {'required': ['id']}, @@ -181,7 +181,7 @@ class GitlabCLI(object): def do_project_all(self, cls, gl, what, args): try: - return gl.projects.all() + return gl.projects.all(all=args['all']) except Exception as e: _die("Impossible to list all projects", e) @@ -430,12 +430,21 @@ def _populate_sub_parser_by_class(cls, sub_parser): for x in attrs] if cls in EXTRA_ACTIONS: + def _add_arg(parser, required, data): + extra_args = {} + if isinstance(data, tuple): + if data[1] is bool: + extra_args = {'action': 'store_true'} + data = data[0] + + parser.add_argument("--%s" % data, required=required, **extra_args) + for action_name in sorted(EXTRA_ACTIONS[cls]): sub_parser_action = sub_parser.add_parser(action_name) d = EXTRA_ACTIONS[cls][action_name] - [sub_parser_action.add_argument("--%s" % arg, required=True) + [_add_arg(sub_parser_action, True, arg) for arg in d.get('required', [])] - [sub_parser_action.add_argument("--%s" % arg, required=False) + [_add_arg(sub_parser_action, False, arg) for arg in d.get('optional', [])] |