@@ -68,21 +68,12 @@ def clsToWhat(cls):
68
68
69
69
70
70
def populate_sub_parser_by_class (cls , sub_parser ):
71
- sub_parser_class = sub_parser .add_subparsers (
72
- dest = 'action' ,
73
- title = "positional argument" ,
74
- description = 'action with %s' % cls .__name__ ,
75
- help = 'action to do'
76
- )
77
71
for action_name in ACTIONS :
78
72
attr = 'can' + action_name .capitalize ()
79
- try :
80
- y = cls .__dict__ [attr ]
81
- except AttributeError :
82
- y = gitlab .GitlabObject .__dict__ [attr ]
73
+ y = getattr (cls , attr ) or getattr (gitlab .GitlabObject , attr )
83
74
if not y :
84
75
continue
85
- sub_parser_action = sub_parser_class .add_parser (action_name )
76
+ sub_parser_action = sub_parser .add_parser (action_name )
86
77
[sub_parser_action .add_argument ("--%s" % x .replace ('_' , '-' ),
87
78
required = True )
88
79
for x in cls .requiredUrlAttrs ]
@@ -119,7 +110,7 @@ def populate_sub_parser_by_class(cls, sub_parser):
119
110
120
111
if cls in extra_actions :
121
112
for action_name in sorted (extra_actions [cls ]):
122
- sub_parser_action = sub_parser_class .add_parser (action_name )
113
+ sub_parser_action = sub_parser .add_parser (action_name )
123
114
d = extra_actions [cls ][action_name ]
124
115
[sub_parser_action .add_argument ("--%s" % arg , required = True )
125
116
for arg in d ['requiredAttrs' ]]
@@ -235,32 +226,37 @@ def do_project_owned():
235
226
if __name__ == "__main__" :
236
227
ssl_verify = True
237
228
timeout = 60
229
+
238
230
parser = argparse .ArgumentParser (
239
- description = ' GitLab API Command Line Interface' )
240
- parser .add_argument ("-v" , "--verbosity " , "--fancy" ,
231
+ description = " GitLab API Command Line Interface" )
232
+ parser .add_argument ("-v" , "--verbose " , "--fancy" ,
241
233
help = "increase output verbosity" ,
242
234
action = "store_true" )
243
- parser .add_argument ("--gitlab" , metavar = 'gitlab' ,
235
+ parser .add_argument ("--gitlab" ,
244
236
help = ("Specifies which python-gitlab.cfg "
245
237
"configuration section should be used. "
246
238
"If not defined, the default selection "
247
239
"will be used." ),
248
240
required = False )
249
- subparsers = parser .add_subparsers (
250
- dest = 'what' ,
251
- title = "positional argument" ,
252
- description = 'GitLab object' ,
253
- help = 'GitLab object'
254
- )
241
+
242
+ subparsers = parser .add_subparsers (dest = 'what' )
255
243
256
244
# populate argparse for all Gitlab Object
245
+ classes = []
257
246
for cls in gitlab .__dict__ .values ():
258
247
try :
259
248
if gitlab .GitlabObject in getmro (cls ):
260
- sub_parser = subparsers .add_parser (clsToWhat (cls ))
261
- populate_sub_parser_by_class (cls , sub_parser )
262
- except Exception :
249
+ classes .append (cls )
250
+ except AttributeError :
263
251
pass
252
+ classes .sort ()
253
+
254
+ for cls in classes :
255
+ arg_name = clsToWhat (cls )
256
+ object_group = subparsers .add_parser (arg_name )
257
+
258
+ object_subparsers = object_group .add_subparsers (dest = 'action' )
259
+ populate_sub_parser_by_class (cls , object_subparsers )
264
260
265
261
arg = parser .parse_args ()
266
262
d = arg .__dict__
@@ -272,7 +268,7 @@ if __name__ == "__main__":
272
268
gitlab_id = arg .gitlab
273
269
# conflicts with "gitlab" attribute from GitlabObject class
274
270
d .pop ("gitlab" )
275
- verbose = arg .verbosity
271
+ verbose = arg .verbose
276
272
action = arg .action
277
273
what = arg .what
278
274
0 commit comments