summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2022-06-05 08:17:15 -0700
committerJohn L. Villalovos <john@sodarock.com>2022-06-05 08:17:15 -0700
commitfb3f28a053f0dcf0a110bb8b6fd11696b4ba3dd9 (patch)
treeaa8e9672de5efd7c84e54ccb1ba4f123e45ce1d6
parent6cdccd90177a70835db176155cf6d0dde70989d3 (diff)
downloadgitlab-fb3f28a053f0dcf0a110bb8b6fd11696b4ba3dd9.tar.gz
chore: rename `whaction` and `action` to `resource_action` in CLI
Rename the variables `whaction` and `action` to `resource_action` to improve code-readability.
-rw-r--r--gitlab/cli.py8
-rw-r--r--gitlab/v4/cli.py31
-rw-r--r--tests/unit/test_cli.py2
3 files changed, 27 insertions, 14 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py
index c9e182d..e418714 100644
--- a/gitlab/cli.py
+++ b/gitlab/cli.py
@@ -323,8 +323,8 @@ def main() -> None:
if args.fields:
fields = [x.strip() for x in args.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
@@ -334,7 +334,7 @@ def main() -> None:
"verbose",
"debug",
"gitlab_resource",
- "whaction",
+ "resource_action",
"version",
"output",
"fields",
@@ -361,4 +361,6 @@ def main() -> None:
if debug:
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
+ )
diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py
index c4e15fc..da203ff 100644
--- a/gitlab/v4/cli.py
+++ b/gitlab/v4/cli.py
@@ -29,14 +29,18 @@ from gitlab import cli
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] = {}
@@ -80,13 +84,13 @@ class GitlabCLI:
del self.args[key]
def run(self) -> Any:
- # Check for a method that matches object + action
- method = f"do_{self.gitlab_resource}_{self.action}"
+ # Check for a method that matches gitlab_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)()
@@ -95,7 +99,7 @@ class GitlabCLI:
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:
@@ -111,7 +115,7 @@ class GitlabCLI:
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:
@@ -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
@@ -498,13 +504,18 @@ PRINTERS: Dict[
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]()
diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py
index 2da8ddf..ef33b5d 100644
--- a/tests/unit/test_cli.py
+++ b/tests/unit/test_cli.py
@@ -126,7 +126,7 @@ def test_v4_parse_args():
parser = cli._get_parser()
args = parser.parse_args(["project", "list"])
assert args.gitlab_resource == "project"
- assert args.whaction == "list"
+ assert args.resource_action == "list"
def test_v4_parser():