2929
3030class GitlabCLI :
3131def __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 ],
3337 )-> None :
3438self .cls :Type [gitlab .base .RESTObject ]= cli .gitlab_resource_to_cls (
3539gitlab_resource ,namespace = gitlab .v4 .objects
3640 )
3741self .cls_name = self .cls .__name__
3842self .gitlab_resource = gitlab_resource .replace ("-" ,"_" )
39- self .action = action .lower ()
43+ self .resource_action = resource_action .lower ()
4044self .gl = gl
4145self .args = args
4246self .parent_args :Dict [str ,Any ]= {}
@@ -80,13 +84,13 @@ def _process_from_parent_attrs(self) -> None:
8084del self .args [key ]
8185
8286def 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 } "
8589if hasattr (self ,method ):
8690return getattr (self ,method )()
8791
8892# Fallback to standard actions (get, list, create, ...)
89- method = f"do_{ self .action } "
93+ method = f"do_{ self .resource_action } "
9094if hasattr (self ,method ):
9195return getattr (self ,method )()
9296
@@ -95,7 +99,7 @@ def run(self) -> Any:
9599
96100def do_custom (self )-> Any :
97101class_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 ]
99103
100104# Get the object (lazy), then act
101105if in_obj :
@@ -111,7 +115,7 @@ def do_custom(self) -> Any:
111115else :
112116class_instance = self .mgr
113117
114- method_name = self .action .replace ("-" ,"_" )
118+ method_name = self .resource_action .replace ("-" ,"_" )
115119return getattr (class_instance ,method_name )(** self .args )
116120
117121def do_project_export_download (self )-> None :
@@ -351,7 +355,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
351355object_group = subparsers .add_parser (arg_name )
352356
353357object_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." ,
355361 )
356362_populate_sub_parser_by_class (cls ,object_subparsers )
357363object_subparsers .required = True
@@ -498,13 +504,18 @@ def display_list(
498504def run (
499505gl :gitlab .Gitlab ,
500506gitlab_resource :str ,
501- action :str ,
507+ resource_action :str ,
502508args :Dict [str ,Any ],
503509verbose :bool ,
504510output :str ,
505511fields :List [str ],
506512)-> 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+ )
508519data = g_cli .run ()
509520
510521printer :Union [JSONPrinter ,LegacyPrinter ,YAMLPrinter ]= PRINTERS [output ]()