| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 74db84c commit 61d8679
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | import argparse | |
| 2 | + import dataclasses | ||
| 2 | 3 | import functools | |
| 3 | 4 | import os | |
| 4 | 5 | import pathlib | |
@@ -29,12 +30,20 @@ | |||
| 29 | 30 | camel_upperlower_regex = re.compile(r"([A-Z]+)([A-Z][a-z])") | |
| 30 | 31 | camel_lowerupper_regex = re.compile(r"([a-z\d])([A-Z])") | |
| 31 | 32 | ||
| 33 | + | ||
| 34 | + @dataclasses.dataclass | ||
| 35 | + class CustomAction: | ||
| 36 | + required: Tuple[str, ...] | ||
| 37 | + optional: Tuple[str, ...] | ||
| 38 | + in_object: bool | ||
| 39 | + | ||
| 40 | + | ||
| 32 | 41 | # custom_actions = { | |
| 33 | 42 | # cls: { | |
| 34 | 43 | # action: (mandatory_args, optional_args, in_obj), | |
| 35 | 44 | # }, | |
| 36 | 45 | # } | |
| 37 | - custom_actions: Dict[str, Dict[str, Tuple[Tuple[str, ...], Tuple[str, ...], bool]]] = {} | ||
| 46 | + custom_actions: Dict[str, Dict[str, CustomAction]] = {} | ||
| 38 | 47 | ||
| 39 | 48 | ||
| 40 | 49 | # For an explanation of how these type-hints work see: | |
@@ -99,7 +108,9 @@ def wrapped_f(*args: Any, **kwargs: Any) -> Any: | |||
| 99 | 108 | custom_actions[final_name] = {} | |
| 100 | 109 | ||
| 101 | 110 | action = custom_action or f.__name__.replace("_", "-") | |
| 102 | - custom_actions[final_name][action] = (required, optional, in_obj) | ||
| 111 | + custom_actions[final_name][action] = CustomAction( | ||
| 112 | + required=required, optional=optional, in_object=in_obj | ||
| 113 | + ) | ||
| 103 | 114 | ||
| 104 | 115 | return cast(__F, wrapped_f) | |
| 105 | 116 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,7 +82,7 @@ def run(self) -> Any: | |||
| 82 | 82 | ||
| 83 | 83 | def do_custom(self) -> Any: | |
| 84 | 84 | class_instance: Union[gitlab.base.RESTManager, gitlab.base.RESTObject] | |
| 85 | - in_obj = cli.custom_actions[self.cls_name][self.resource_action][2] | ||
| 85 | + in_obj = cli.custom_actions[self.cls_name][self.resource_action].in_object | ||
| 86 | 86 | ||
| 87 | 87 | # Get the object (lazy), then act | |
| 88 | 88 | if in_obj: | |
@@ -321,13 +321,13 @@ def _populate_sub_parser_by_class( | |||
| 321 | 321 | id_attr = cls._id_attr.replace("_", "-") | |
| 322 | 322 | sub_parser_action.add_argument(f"--{id_attr}", required=True) | |
| 323 | 323 | ||
| 324 | - required, optional, dummy = cli.custom_actions[name][action_name] | ||
| 325 | - for x in required: | ||
| 324 | + custom_action = cli.custom_actions[name][action_name] | ||
| 325 | + for x in custom_action.required: | ||
| 326 | 326 | if x != cls._id_attr: | |
| 327 | 327 | sub_parser_action.add_argument( | |
| 328 | 328 | f"--{x.replace('_', '-')}", required=True | |
| 329 | 329 | ) | |
| 330 | - for x in optional: | ||
| 330 | + for x in custom_action.optional: | ||
| 331 | 331 | if x != cls._id_attr: | |
| 332 | 332 | sub_parser_action.add_argument( | |
| 333 | 333 | f"--{x.replace('_', '-')}", required=False | |
@@ -350,13 +350,13 @@ def _populate_sub_parser_by_class( | |||
| 350 | 350 | ) | |
| 351 | 351 | sub_parser_action.add_argument("--sudo", required=False) | |
| 352 | 352 | ||
| 353 | - required, optional, dummy = cli.custom_actions[name][action_name] | ||
| 354 | - for x in required: | ||
| 353 | + custom_action = cli.custom_actions[name][action_name] | ||
| 354 | + for x in custom_action.required: | ||
| 355 | 355 | if x != cls._id_attr: | |
| 356 | 356 | sub_parser_action.add_argument( | |
| 357 | 357 | f"--{x.replace('_', '-')}", required=True | |
| 358 | 358 | ) | |
| 359 | - for x in optional: | ||
| 359 | + for x in custom_action.optional: | ||
| 360 | 360 | if x != cls._id_attr: | |
| 361 | 361 | sub_parser_action.add_argument( | |
| 362 | 362 | f"--{x.replace('_', '-')}", required=False | |
| Back | FazBrowse Home | New Git URL |
0 commit comments