@@ -44,7 +44,7 @@ UNPROTECT = 'unprotect'
4444SEARCH = 'search'
4545OWNED = 'owned'
4646ALL = 'all'
47- ACTION = [LIST , GET , CREATE , UPDATE , DELETE ]
47+ ACTIONS = [LIST , GET , CREATE , UPDATE , DELETE ]
4848EXTRA_ACTION = [PROTECT , UNPROTECT , SEARCH , OWNED , ALL ]
4949
5050extra_actions = {
@@ -78,7 +78,7 @@ def populate_sub_parser_by_class(cls, sub_parser):
7878 description = 'action with %s' % cls .__name__ ,
7979 help = 'action to do'
8080 )
81- for action_name in ACTION :
81+ for action_name in ACTIONS :
8282 attr = 'can' + action_name .capitalize ()
8383 try :
8484 y = cls .__dict__ [attr ]
@@ -87,14 +87,15 @@ def populate_sub_parser_by_class(cls, sub_parser):
8787 if not y :
8888 continue
8989 sub_parser_action = sub_parser_class .add_parser (action_name )
90+ [sub_parser_action .add_argument ("--%s" % x .replace ('_' , '-' ), required = True ) for x in cls .requiredUrlAttrs ]
9091 if action_name == LIST :
9192 [sub_parser_action .add_argument ("--%s" % x .replace ('_' , '-' ), required = True ) for x in cls .requiredListAttrs ]
9293 sub_parser_action .add_argument ("--page" , required = False )
9394 sub_parser_action .add_argument ("--per-page" , required = False )
9495 elif action_name in [GET , DELETE ]:
9596 if cls not in [gitlab .CurrentUser ]:
9697 sub_parser_action .add_argument ("--id" , required = True )
97- [sub_parser_action .add_argument ("--%s" % x .replace ('_' , '-' )) for x in cls .requiredGetAttrs ]
98+ [sub_parser_action .add_argument ("--%s" % x .replace ('_' , '-' ), required = True ) for x in cls .requiredGetAttrs ]
9899 elif action_name == CREATE :
99100 [sub_parser_action .add_argument ("--%s" % x .replace ('_' , '-' ), required = True ) for x in
100101 cls .requiredCreateAttrs ]
@@ -304,29 +305,15 @@ if __name__ == "__main__":
304305 o .display (verbose )
305306 print ("" )
306307
307- elif action == GET :
308- o = do_get (cls , d )
309- o .display (verbose )
310-
311- elif action == DELETE :
312- o = do_delete (cls , d )
313-
314- elif action == UPDATE :
315- o = do_update (cls , d )
316-
317- elif action == PROTECT :
318- if cls != gitlab .ProjectBranch :
319- die ("%s objects can't be protected" % what )
320-
321- o = do_get (cls , d )
322- o .protect ()
308+ elif action == DELETE or action == UPDATE :
309+ o = globals ()['do_%s' % action .lower ()](cls , d )
323310
324- elif action == UNPROTECT :
311+ elif action == PROTECT or action == UNPROTECT :
325312 if cls != gitlab .ProjectBranch :
326313 die ("%s objects can't be protected" % what )
327314
328315 o = do_get (cls , d )
329- o . unprotect ()
316+ getattr ( o , action ) ()
330317
331318 elif action == SEARCH :
332319 if cls != gitlab .Project :
0 commit comments