Skip to content

Commit f5f734e

Browse files
author
Gauvain Pocentek
committed
CLI: add support for project all --all
Rework the extra opts definition to allow setting typed arguments. Fixes #153
1 parent e64d0b9 commit f5f734e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

gitlab/cli.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
gitlab.ProjectMilestone: {'issues': {'required': ['id', 'project-id']}},
5959
gitlab.Project: {'search': {'required': ['query']},
6060
'owned': {},
61-
'all': {},
61+
'all': {'optional': [('all', bool)]},
6262
'starred': {},
6363
'star': {'required': ['id']},
6464
'unstar': {'required': ['id']},
@@ -181,7 +181,7 @@ def do_project_search(self, cls, gl, what, args):
181181

182182
def do_project_all(self, cls, gl, what, args):
183183
try:
184-
return gl.projects.all()
184+
return gl.projects.all(all=args['all'])
185185
except Exception as e:
186186
_die("Impossible to list all projects", e)
187187

@@ -430,12 +430,21 @@ def _populate_sub_parser_by_class(cls, sub_parser):
430430
for x in attrs]
431431

432432
if cls in EXTRA_ACTIONS:
433+
def _add_arg(parser, required, data):
434+
extra_args = {}
435+
if isinstance(data, tuple):
436+
if data[1] is bool:
437+
extra_args = {'action': 'store_true'}
438+
data = data[0]
439+
440+
parser.add_argument("--%s" % data, required=required, **extra_args)
441+
433442
for action_name in sorted(EXTRA_ACTIONS[cls]):
434443
sub_parser_action = sub_parser.add_parser(action_name)
435444
d = EXTRA_ACTIONS[cls][action_name]
436-
[sub_parser_action.add_argument("--%s" % arg, required=True)
445+
[_add_arg(sub_parser_action, True, arg)
437446
for arg in d.get('required', [])]
438-
[sub_parser_action.add_argument("--%s" % arg, required=False)
447+
[_add_arg(sub_parser_action, False, arg)
439448
for arg in d.get('optional', [])]
440449

441450

0 commit comments

Comments
 (0)