| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6cdccd9 commit fb3f28a
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -323,8 +323,8 @@ def main() -> None: | |||
| 323 | 323 | if args.fields: | |
| 324 | 324 | fields = [x.strip() for x in args.fields.split(",")] | |
| 325 | 325 | debug = args.debug | |
| 326 | - action = args.whaction | ||
| 327 | 326 | gitlab_resource = args.gitlab_resource | |
| 327 | + resource_action = args.resource_action | ||
| 328 | 328 | ||
| 329 | 329 | args_dict = vars(args) | |
| 330 | 330 | # Remove CLI behavior-related args | |
@@ -334,7 +334,7 @@ def main() -> None: | |||
| 334 | 334 | "verbose", | |
| 335 | 335 | "debug", | |
| 336 | 336 | "gitlab_resource", | |
| 337 | - "whaction", | ||
| 337 | + "resource_action", | ||
| 338 | 338 | "version", | |
| 339 | 339 | "output", | |
| 340 | 340 | "fields", | |
@@ -361,4 +361,6 @@ def main() -> None: | |||
| 361 | 361 | if debug: | |
| 362 | 362 | gl.enable_debug() | |
| 363 | 363 | ||
| 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 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,14 +29,18 @@ | |||
| 29 | 29 | ||
| 30 | 30 | class GitlabCLI: | |
| 31 | 31 | 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], | ||
| 33 | 37 | ) -> None: | |
| 34 | 38 | self.cls: Type[gitlab.base.RESTObject] = cli.gitlab_resource_to_cls( | |
| 35 | 39 | gitlab_resource, namespace=gitlab.v4.objects | |
| 36 | 40 | ) | |
| 37 | 41 | self.cls_name = self.cls.__name__ | |
| 38 | 42 | self.gitlab_resource = gitlab_resource.replace("-", "_") | |
| 39 | - self.action = action.lower() | ||
| 43 | + self.resource_action = resource_action.lower() | ||
| 40 | 44 | self.gl = gl | |
| 41 | 45 | self.args = args | |
| 42 | 46 | self.parent_args: Dict[str, Any] = {} | |
@@ -80,13 +84,13 @@ def _process_from_parent_attrs(self) -> None: | |||
| 80 | 84 | del self.args[key] | |
| 81 | 85 | ||
| 82 | 86 | 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}" | ||
| 85 | 89 | if hasattr(self, method): | |
| 86 | 90 | return getattr(self, method)() | |
| 87 | 91 | ||
| 88 | 92 | # Fallback to standard actions (get, list, create, ...) | |
| 89 | - method = f"do_{self.action}" | ||
| 93 | + method = f"do_{self.resource_action}" | ||
| 90 | 94 | if hasattr(self, method): | |
| 91 | 95 | return getattr(self, method)() | |
| 92 | 96 | ||
@@ -95,7 +99,7 @@ def run(self) -> Any: | |||
| 95 | 99 | ||
| 96 | 100 | def do_custom(self) -> Any: | |
| 97 | 101 | 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] | ||
| 99 | 103 | ||
| 100 | 104 | # Get the object (lazy), then act | |
| 101 | 105 | if in_obj: | |
@@ -111,7 +115,7 @@ def do_custom(self) -> Any: | |||
| 111 | 115 | else: | |
| 112 | 116 | class_instance = self.mgr | |
| 113 | 117 | ||
| 114 | - method_name = self.action.replace("-", "_") | ||
| 118 | + method_name = self.resource_action.replace("-", "_") | ||
| 115 | 119 | return getattr(class_instance, method_name)(**self.args) | |
| 116 | 120 | ||
| 117 | 121 | def do_project_export_download(self) -> None: | |
@@ -351,7 +355,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: | |||
| 351 | 355 | object_group = subparsers.add_parser(arg_name) | |
| 352 | 356 | ||
| 353 | 357 | 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.", | ||
| 355 | 361 | ) | |
| 356 | 362 | _populate_sub_parser_by_class(cls, object_subparsers) | |
| 357 | 363 | object_subparsers.required = True | |
@@ -498,13 +504,18 @@ def display_list( | |||
| 498 | 504 | def run( | |
| 499 | 505 | gl: gitlab.Gitlab, | |
| 500 | 506 | gitlab_resource: str, | |
| 501 | - action: str, | ||
| 507 | + resource_action: str, | ||
| 502 | 508 | args: Dict[str, Any], | |
| 503 | 509 | verbose: bool, | |
| 504 | 510 | output: str, | |
| 505 | 511 | fields: List[str], | |
| 506 | 512 | ) -> 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 | + ) | ||
| 508 | 519 | data = g_cli.run() | |
| 509 | 520 | ||
| 510 | 521 | printer: Union[JSONPrinter, LegacyPrinter, YAMLPrinter] = PRINTERS[output]() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,7 +126,7 @@ def test_v4_parse_args(): | |||
| 126 | 126 | parser = cli._get_parser() | |
| 127 | 127 | args = parser.parse_args(["project", "list"]) | |
| 128 | 128 | assert args.gitlab_resource == "project" | |
| 129 | - assert args.whaction == "list" | ||
| 129 | + assert args.resource_action == "list" | ||
| 130 | 130 | ||
| 131 | 131 | ||
| 132 | 132 | def test_v4_parser(): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments