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

chore: renamewhaction andaction toresource_action in CLI#2054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nejch merged 1 commit intomainfromjlvillal/resource
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletionsgitlab/cli.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -323,8 +323,8 @@ def main() -> None:
ifargs.fields:
fields= [x.strip()forxinargs.fields.split(",")]
debug=args.debug
action=args.whaction
gitlab_resource=args.gitlab_resource
resource_action=args.resource_action

args_dict=vars(args)
# Remove CLI behavior-related args
Expand All@@ -334,7 +334,7 @@ def main() -> None:
"verbose",
"debug",
"gitlab_resource",
"whaction",
"resource_action",
"version",
"output",
"fields",
Expand All@@ -361,4 +361,6 @@ def main() -> None:
ifdebug:
gl.enable_debug()

gitlab.v4.cli.run(gl,gitlab_resource,action,args_dict,verbose,output,fields)
gitlab.v4.cli.run(
gl,gitlab_resource,resource_action,args_dict,verbose,output,fields
)
31 changes: 21 additions & 10 deletionsgitlab/v4/cli.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,14 +29,18 @@

class GitlabCLI:
def __init__(
self, gl: gitlab.Gitlab, gitlab_resource: str, action: str, args: Dict[str, str]
self,
gl: gitlab.Gitlab,
gitlab_resource: str,
resource_action: str,
args: Dict[str, str],
) -> None:
self.cls: Type[gitlab.base.RESTObject] = cli.gitlab_resource_to_cls(
gitlab_resource, namespace=gitlab.v4.objects
)
self.cls_name = self.cls.__name__
self.gitlab_resource = gitlab_resource.replace("-", "_")
self.action =action.lower()
self.resource_action =resource_action.lower()
self.gl = gl
self.args = args
self.parent_args: Dict[str, Any] = {}
Expand DownExpand Up@@ -80,13 +84,13 @@ def _process_from_parent_attrs(self) -> None:
del self.args[key]

def run(self) -> Any:
# Check for a method that matchesobject + action
method = f"do_{self.gitlab_resource}_{self.action}"
# Check for a method that matchesgitlab_resource + action
method = f"do_{self.gitlab_resource}_{self.resource_action}"
if hasattr(self, method):
return getattr(self, method)()

# Fallback to standard actions (get, list, create, ...)
method = f"do_{self.action}"
method = f"do_{self.resource_action}"
if hasattr(self, method):
return getattr(self, method)()

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

def do_custom(self) -> Any:
class_instance: Union[gitlab.base.RESTManager, gitlab.base.RESTObject]
in_obj = cli.custom_actions[self.cls_name][self.action][2]
in_obj = cli.custom_actions[self.cls_name][self.resource_action][2]

# Get the object (lazy), then act
if in_obj:
Expand All@@ -111,7 +115,7 @@ def do_custom(self) -> Any:
else:
class_instance = self.mgr

method_name = self.action.replace("-", "_")
method_name = self.resource_action.replace("-", "_")
return getattr(class_instance, method_name)(**self.args)

def do_project_export_download(self) -> None:
Expand DownExpand Up@@ -351,7 +355,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
object_group = subparsers.add_parser(arg_name)

object_subparsers = object_group.add_subparsers(
title="action", dest="whaction", help="Action to execute."
title="action",
dest="resource_action",
help="Action to execute on the GitLab resource.",
)
_populate_sub_parser_by_class(cls, object_subparsers)
object_subparsers.required = True
Expand DownExpand Up@@ -498,13 +504,18 @@ def display_list(
def run(
gl: gitlab.Gitlab,
gitlab_resource: str,
action: str,
resource_action: str,
args: Dict[str, Any],
verbose: bool,
output: str,
fields: List[str],
) -> None:
g_cli = GitlabCLI(gl=gl, gitlab_resource=gitlab_resource, action=action, args=args)
g_cli = GitlabCLI(
gl=gl,
gitlab_resource=gitlab_resource,
resource_action=resource_action,
args=args,
)
data = g_cli.run()

printer: Union[JSONPrinter, LegacyPrinter, YAMLPrinter] = PRINTERS[output]()
Expand Down
2 changes: 1 addition & 1 deletiontests/unit/test_cli.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,7 +126,7 @@ def test_v4_parse_args():
parser=cli._get_parser()
args=parser.parse_args(["project","list"])
assertargs.gitlab_resource=="project"
assertargs.whaction=="list"
assertargs.resource_action=="list"


deftest_v4_parser():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp