| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,14 +91,16 @@ def die(msg: str, e: Optional[Exception] = None) -> None: | |||
| 91 | 91 | sys.exit(1) | |
| 92 | 92 | ||
| 93 | 93 | ||
| 94 | - def what_to_cls(what: str, namespace: ModuleType) -> Type[RESTObject]: | ||
| 94 | + def gitlab_resource_to_cls( | ||
| 95 | + gitlab_resource: str, namespace: ModuleType | ||
| 96 | + ) -> Type[RESTObject]: | ||
| 95 | 97 | classes = CaseInsensitiveDict(namespace.__dict__) | |
| 96 | - lowercase_class = what.replace("-", "") | ||
| 98 | + lowercase_class = gitlab_resource.replace("-", "") | ||
| 97 | 99 | ||
| 98 | 100 | return classes[lowercase_class] | |
| 99 | 101 | ||
| 100 | 102 | ||
| 101 | - def cls_to_what(cls: RESTObject) -> str: | ||
| 103 | + def cls_to_gitlab_resource(cls: RESTObject) -> str: | ||
| 102 | 104 | dasherized_uppercase = camel_upperlower_regex.sub(r"\1-\2", cls.__name__) | |
| 103 | 105 | dasherized_lowercase = camel_lowerupper_regex.sub(r"\1-\2", dasherized_uppercase) | |
| 104 | 106 | return dasherized_lowercase.lower() | |
@@ -322,7 +324,7 @@ def main() -> None: | |||
| 322 | 324 | fields = [x.strip() for x in args.fields.split(",")] | |
| 323 | 325 | debug = args.debug | |
| 324 | 326 | action = args.whaction | |
| 325 | - what = args.what | ||
| 327 | + gitlab_resource = args.gitlab_resource | ||
| 326 | 328 | ||
| 327 | 329 | args_dict = vars(args) | |
| 328 | 330 | # Remove CLI behavior-related args | |
@@ -331,7 +333,7 @@ def main() -> None: | |||
| 331 | 333 | "config_file", | |
| 332 | 334 | "verbose", | |
| 333 | 335 | "debug", | |
| 334 | - "what", | ||
| 336 | + "gitlab_resource", | ||
| 335 | 337 | "whaction", | |
| 336 | 338 | "version", | |
| 337 | 339 | "output", | |
@@ -359,4 +361,4 @@ def main() -> None: | |||
| 359 | 361 | if debug: | |
| 360 | 362 | gl.enable_debug() | |
| 361 | 363 | ||
| 362 | - gitlab.v4.cli.run(gl, what, action, args_dict, verbose, output, fields) | ||
| 364 | + gitlab.v4.cli.run(gl, gitlab_resource, action, args_dict, verbose, output, fields) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,13 +29,13 @@ | |||
| 29 | 29 | ||
| 30 | 30 | class GitlabCLI: | |
| 31 | 31 | def __init__( | |
| 32 | - self, gl: gitlab.Gitlab, what: str, action: str, args: Dict[str, str] | ||
| 32 | + self, gl: gitlab.Gitlab, gitlab_resource: str, action: str, args: Dict[str, str] | ||
| 33 | 33 | ) -> None: | |
| 34 | - self.cls: Type[gitlab.base.RESTObject] = cli.what_to_cls( | ||
| 35 | - what, namespace=gitlab.v4.objects | ||
| 34 | + self.cls: Type[gitlab.base.RESTObject] = cli.gitlab_resource_to_cls( | ||
| 35 | + gitlab_resource, namespace=gitlab.v4.objects | ||
| 36 | 36 | ) | |
| 37 | 37 | self.cls_name = self.cls.__name__ | |
| 38 | - self.what = what.replace("-", "_") | ||
| 38 | + self.gitlab_resource = gitlab_resource.replace("-", "_") | ||
| 39 | 39 | self.action = action.lower() | |
| 40 | 40 | self.gl = gl | |
| 41 | 41 | self.args = args | |
@@ -81,7 +81,7 @@ def _process_from_parent_attrs(self) -> None: | |||
| 81 | 81 | ||
| 82 | 82 | def run(self) -> Any: | |
| 83 | 83 | # Check for a method that matches object + action | |
| 84 | - method = f"do_{self.what}_{self.action}" | ||
| 84 | + method = f"do_{self.gitlab_resource}_{self.action}" | ||
| 85 | 85 | if hasattr(self, method): | |
| 86 | 86 | return getattr(self, method)() | |
| 87 | 87 | ||
@@ -333,7 +333,7 @@ def _populate_sub_parser_by_class( | |||
| 333 | 333 | ||
| 334 | 334 | def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: | |
| 335 | 335 | subparsers = parser.add_subparsers( | |
| 336 | - title="object", dest="what", help="Object to manipulate." | ||
| 336 | + title="object", dest="gitlab_resource", help="Object to manipulate." | ||
| 337 | 337 | ) | |
| 338 | 338 | subparsers.required = True | |
| 339 | 339 | ||
@@ -347,7 +347,7 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: | |||
| 347 | 347 | classes.add(cls._obj_cls) | |
| 348 | 348 | ||
| 349 | 349 | for cls in sorted(classes, key=operator.attrgetter("__name__")): | |
| 350 | - arg_name = cli.cls_to_what(cls) | ||
| 350 | + arg_name = cli.cls_to_gitlab_resource(cls) | ||
| 351 | 351 | object_group = subparsers.add_parser(arg_name) | |
| 352 | 352 | ||
| 353 | 353 | object_subparsers = object_group.add_subparsers( | |
@@ -497,14 +497,14 @@ def display_list( | |||
| 497 | 497 | ||
| 498 | 498 | def run( | |
| 499 | 499 | gl: gitlab.Gitlab, | |
| 500 | - what: str, | ||
| 500 | + gitlab_resource: str, | ||
| 501 | 501 | action: str, | |
| 502 | 502 | args: Dict[str, Any], | |
| 503 | 503 | verbose: bool, | |
| 504 | 504 | output: str, | |
| 505 | 505 | fields: List[str], | |
| 506 | 506 | ) -> None: | |
| 507 | - g_cli = GitlabCLI(gl=gl, what=what, action=action, args=args) | ||
| 507 | + g_cli = GitlabCLI(gl=gl, gitlab_resource=gitlab_resource, action=action, args=args) | ||
| 508 | 508 | data = g_cli.run() | |
| 509 | 509 | ||
| 510 | 510 | printer: Union[JSONPrinter, LegacyPrinter, YAMLPrinter] = PRINTERS[output]() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,7 @@ | |||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | 31 | @pytest.mark.parametrize( | |
| 32 | - "what,expected_class", | ||
| 32 | + "gitlab_resource,expected_class", | ||
| 33 | 33 | [ | |
| 34 | 34 | ("class", "Class"), | |
| 35 | 35 | ("test-class", "TestClass"), | |
@@ -39,18 +39,18 @@ | |||
| 39 | 39 | ("ldap-group", "LDAPGroup"), | |
| 40 | 40 | ], | |
| 41 | 41 | ) | |
| 42 | - def test_what_to_cls(what, expected_class): | ||
| 42 | + def test_gitlab_resource_to_cls(gitlab_resource, expected_class): | ||
| 43 | 43 | def _namespace(): | |
| 44 | 44 | pass | |
| 45 | 45 | ||
| 46 | 46 | ExpectedClass = type(expected_class, (), {}) | |
| 47 | 47 | _namespace.__dict__[expected_class] = ExpectedClass | |
| 48 | 48 | ||
| 49 | - assert cli.what_to_cls(what, _namespace) == ExpectedClass | ||
| 49 | + assert cli.gitlab_resource_to_cls(gitlab_resource, _namespace) == ExpectedClass | ||
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | 52 | @pytest.mark.parametrize( | |
| 53 | - "class_name,expected_what", | ||
| 53 | + "class_name,expected_gitlab_resource", | ||
| 54 | 54 | [ | |
| 55 | 55 | ("Class", "class"), | |
| 56 | 56 | ("TestClass", "test-class"), | |
@@ -61,10 +61,10 @@ def _namespace(): | |||
| 61 | 61 | ("LDAPGroup", "ldap-group"), | |
| 62 | 62 | ], | |
| 63 | 63 | ) | |
| 64 | - def test_cls_to_what(class_name, expected_what): | ||
| 64 | + def test_cls_to_gitlab_resource(class_name, expected_gitlab_resource): | ||
| 65 | 65 | TestClass = type(class_name, (), {}) | |
| 66 | 66 | ||
| 67 | - assert cli.cls_to_what(TestClass) == expected_what | ||
| 67 | + assert cli.cls_to_gitlab_resource(TestClass) == expected_gitlab_resource | ||
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | 70 | @pytest.mark.parametrize( | |
@@ -125,7 +125,7 @@ def test_base_parser(): | |||
| 125 | 125 | def test_v4_parse_args(): | |
| 126 | 126 | parser = cli._get_parser() | |
| 127 | 127 | args = parser.parse_args(["project", "list"]) | |
| 128 | - assert args.what == "project" | ||
| 128 | + assert args.gitlab_resource == "project" | ||
| 129 | 129 | assert args.whaction == "list" | |
| 130 | 130 | ||
| 131 | 131 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments