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