29
29
30
30
class GitlabCLI :
31
31
def __init__ (
32
- self ,gl :gitlab .Gitlab ,gitlab_resource :str ,action :str ,args :Dict [str ,str ]
32
+ self ,
33
+ gl :gitlab .Gitlab ,
34
+ gitlab_resource :str ,
35
+ resource_action :str ,
36
+ args :Dict [str ,str ],
33
37
)-> None :
34
38
self .cls :Type [gitlab .base .RESTObject ]= cli .gitlab_resource_to_cls (
35
39
gitlab_resource ,namespace = gitlab .v4 .objects
36
40
)
37
41
self .cls_name = self .cls .__name__
38
42
self .gitlab_resource = gitlab_resource .replace ("-" ,"_" )
39
- self .action = action .lower ()
43
+ self .resource_action = resource_action .lower ()
40
44
self .gl = gl
41
45
self .args = args
42
46
self .parent_args :Dict [str ,Any ]= {}
@@ -80,13 +84,13 @@ def _process_from_parent_attrs(self) -> None:
80
84
del self .args [key ]
81
85
82
86
def run (self )-> Any :
83
- # Check for a method that matchesobject + action
84
- method = f"do_{ self .gitlab_resource } _{ self .action } "
87
+ # Check for a method that matchesgitlab_resource + action
88
+ method = f"do_{ self .gitlab_resource } _{ self .resource_action } "
85
89
if hasattr (self ,method ):
86
90
return getattr (self ,method )()
87
91
88
92
# Fallback to standard actions (get, list, create, ...)
89
- method = f"do_{ self .action } "
93
+ method = f"do_{ self .resource_action } "
90
94
if hasattr (self ,method ):
91
95
return getattr (self ,method )()
92
96
@@ -95,7 +99,7 @@ def run(self) -> Any:
95
99
96
100
def do_custom (self )-> Any :
97
101
class_instance :Union [gitlab .base .RESTManager ,gitlab .base .RESTObject ]
98
- in_obj = cli .custom_actions [self .cls_name ][self .action ][2 ]
102
+ in_obj = cli .custom_actions [self .cls_name ][self .resource_action ][2 ]
99
103
100
104
# Get the object (lazy), then act
101
105
if in_obj :
@@ -111,7 +115,7 @@ def do_custom(self) -> Any:
111
115
else :
112
116
class_instance = self .mgr
113
117
114
- method_name = self .action .replace ("-" ,"_" )
118
+ method_name = self .resource_action .replace ("-" ,"_" )
115
119
return getattr (class_instance ,method_name )(** self .args )
116
120
117
121
def do_project_export_download (self )-> None :
@@ -351,7 +355,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
351
355
object_group = subparsers .add_parser (arg_name )
352
356
353
357
object_subparsers = object_group .add_subparsers (
354
- title = "action" ,dest = "whaction" ,help = "Action to execute."
358
+ title = "action" ,
359
+ dest = "resource_action" ,
360
+ help = "Action to execute on the GitLab resource." ,
355
361
)
356
362
_populate_sub_parser_by_class (cls ,object_subparsers )
357
363
object_subparsers .required = True
@@ -498,13 +504,18 @@ def display_list(
498
504
def run (
499
505
gl :gitlab .Gitlab ,
500
506
gitlab_resource :str ,
501
- action :str ,
507
+ resource_action :str ,
502
508
args :Dict [str ,Any ],
503
509
verbose :bool ,
504
510
output :str ,
505
511
fields :List [str ],
506
512
)-> None :
507
- g_cli = GitlabCLI (gl = gl ,gitlab_resource = gitlab_resource ,action = action ,args = args )
513
+ g_cli = GitlabCLI (
514
+ gl = gl ,
515
+ gitlab_resource = gitlab_resource ,
516
+ resource_action = resource_action ,
517
+ args = args ,
518
+ )
508
519
data = g_cli .run ()
509
520
510
521
printer :Union [JSONPrinter ,LegacyPrinter ,YAMLPrinter ]= PRINTERS [output ]()