Skip to content

Commit 2792091

Browse files
committed
improvement argument required for each action
add try/catch for error of parsing of not gitlabObject
1 parent 9439ce4 commit 2792091

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

gitlab

+15-9
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def clsToWhat(cls):
7373
def populate_sub_parser_by_class(cls, sub_parser):
7474
sub_parser_class = sub_parser.add_subparsers(
7575
dest='action',
76-
title="action",
77-
description='action to do',
76+
title="positional argument",
77+
description='action with %s' % cls.__name__,
7878
help='action to do'
7979
)
8080
for action_name in ACTION:
@@ -87,27 +87,29 @@ def populate_sub_parser_by_class(cls, sub_parser):
8787
continue
8888
sub_parser_action = sub_parser_class.add_parser(action_name)
8989
if action_name == LIST:
90-
[sub_parser_action.add_argument("--%s" % x.replace('_', '-')) for x in cls.requiredListAttrs]
90+
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=True) for x in cls.requiredListAttrs]
9191
sub_parser_action.add_argument("--page", required=False)
9292
sub_parser_action.add_argument("--per-page", required=False)
9393
elif action_name in [GET, DELETE]:
9494
if cls not in [gitlab.CurrentUser]:
9595
sub_parser_action.add_argument("--id", required=True)
9696
[sub_parser_action.add_argument("--%s" % x.replace('_', '-')) for x in cls.requiredGetAttrs]
9797
elif action_name == CREATE:
98-
[sub_parser_action.add_argument("--%s" % x.replace('_', '-')) for x in cls.requiredCreateAttrs]
98+
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=True) for x in
99+
cls.requiredCreateAttrs]
99100
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=False) for x in
100101
cls.optionalCreateAttrs]
101102
elif action_name == UPDATE:
102-
[sub_parser_action.add_argument("--%s" % x.replace('_', '-')) for x in cls.requiredCreateAttrs]
103+
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=True) for x in
104+
cls.requiredCreateAttrs]
103105
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'), required=False) for x in
104106
cls.optionalCreateAttrs]
105107

106108
if cls in extra_actions:
107109
for action_name in sorted(extra_actions[cls]):
108110
sub_parser_action = sub_parser_class.add_parser(action_name)
109111
d = extra_actions[cls][action_name]
110-
[sub_parser_action.add_argument("--%s" % arg) for arg in d['requiredAttrs']]
112+
[sub_parser_action.add_argument("--%s" % arg, required=True) for arg in d['requiredAttrs']]
111113

112114

113115
def do_auth():
@@ -228,14 +230,18 @@ if __name__ == "__main__":
228230
subparsers = parser.add_subparsers(
229231
dest='what',
230232
title="what",
233+
title="positional argument",
231234
description='GitLab object',
232235
help='GitLab object'
233236
)
234237
#populate argparse for all Gitlab Object
235238
for cls in gitlab.__dict__.values():
236-
if gitlab.GitlabObject in getmro(cls):
237-
sub_parser = subparsers.add_parser(clsToWhat(cls))
238-
populate_sub_parser_by_class(cls, sub_parser)
239+
try:
240+
if gitlab.GitlabObject in getmro(cls):
241+
sub_parser = subparsers.add_parser(clsToWhat(cls))
242+
populate_sub_parser_by_class(cls, sub_parser)
243+
except:
244+
pass
239245

240246
arg = parser.parse_args()
241247
d = arg.__dict__

0 commit comments

Comments
 (0)