Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd71c68c

Browse files
chore: renamewhaction andaction toresource_action in CLI
Rename the variables `whaction` and `action` to `resource_action` toimprove code-readability.
1 parent6cdccd9 commitd71c68c

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

‎gitlab/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ def main() -> None:
323323
ifargs.fields:
324324
fields= [x.strip()forxinargs.fields.split(",")]
325325
debug=args.debug
326-
action=args.whaction
327326
gitlab_resource=args.gitlab_resource
327+
resource_action=args.resource_action
328328

329329
args_dict=vars(args)
330330
# Remove CLI behavior-related args
@@ -334,7 +334,7 @@ def main() -> None:
334334
"verbose",
335335
"debug",
336336
"gitlab_resource",
337-
"whaction",
337+
"resource_action",
338338
"version",
339339
"output",
340340
"fields",
@@ -361,4 +361,6 @@ def main() -> None:
361361
ifdebug:
362362
gl.enable_debug()
363363

364-
gitlab.v4.cli.run(gl,gitlab_resource,action,args_dict,verbose,output,fields)
364+
gitlab.v4.cli.run(
365+
gl,gitlab_resource,resource_action,args_dict,verbose,output,fields
366+
)

‎gitlab/v4/cli.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@
2929

3030
classGitlabCLI:
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
delself.args[key]
8185

8286
defrun(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}"
8589
ifhasattr(self,method):
8690
returngetattr(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
ifhasattr(self,method):
9195
returngetattr(self,method)()
9296

@@ -95,7 +99,7 @@ def run(self) -> Any:
9599

96100
defdo_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
ifin_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
returngetattr(class_instance,method_name)(**self.args)
116120

117121
defdo_project_export_download(self)->None:
@@ -351,7 +355,7 @@ 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",dest="resource_action",help="Action to execute."
355359
)
356360
_populate_sub_parser_by_class(cls,object_subparsers)
357361
object_subparsers.required=True
@@ -498,13 +502,18 @@ def display_list(
498502
defrun(
499503
gl:gitlab.Gitlab,
500504
gitlab_resource:str,
501-
action:str,
505+
resource_action:str,
502506
args:Dict[str,Any],
503507
verbose:bool,
504508
output:str,
505509
fields:List[str],
506510
)->None:
507-
g_cli=GitlabCLI(gl=gl,gitlab_resource=gitlab_resource,action=action,args=args)
511+
g_cli=GitlabCLI(
512+
gl=gl,
513+
gitlab_resource=gitlab_resource,
514+
resource_action=resource_action,
515+
args=args,
516+
)
508517
data=g_cli.run()
509518

510519
printer:Union[JSONPrinter,LegacyPrinter,YAMLPrinter]=PRINTERS[output]()

‎tests/unit/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_v4_parse_args():
126126
parser=cli._get_parser()
127127
args=parser.parse_args(["project","list"])
128128
assertargs.gitlab_resource=="project"
129-
assertargs.whaction=="list"
129+
assertargs.resource_action=="list"
130130

131131

132132
deftest_v4_parser():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp