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

Commit61d8679

Browse files
chore: create a CustomAction dataclass
1 parent74db84c commit61d8679

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

‎gitlab/cli.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importargparse
2+
importdataclasses
23
importfunctools
34
importos
45
importpathlib
@@ -29,12 +30,20 @@
2930
camel_upperlower_regex=re.compile(r"([A-Z]+)([A-Z][a-z])")
3031
camel_lowerupper_regex=re.compile(r"([a-z\d])([A-Z])")
3132

33+
34+
@dataclasses.dataclass
35+
classCustomAction:
36+
required:Tuple[str, ...]
37+
optional:Tuple[str, ...]
38+
in_object:bool
39+
40+
3241
# custom_actions = {
3342
# cls: {
3443
# action: (mandatory_args, optional_args, in_obj),
3544
# },
3645
# }
37-
custom_actions:Dict[str,Dict[str,Tuple[Tuple[str, ...],Tuple[str, ...],bool]]]= {}
46+
custom_actions:Dict[str,Dict[str,CustomAction]]= {}
3847

3948

4049
# For an explanation of how these type-hints work see:
@@ -99,7 +108,9 @@ def wrapped_f(*args: Any, **kwargs: Any) -> Any:
99108
custom_actions[final_name]= {}
100109

101110
action=custom_actionorf.__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+
)
103114

104115
returncast(__F,wrapped_f)
105116

‎gitlab/v4/cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run(self) -> Any:
8282

8383
defdo_custom(self)->Any:
8484
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
8686

8787
# Get the object (lazy), then act
8888
ifin_obj:
@@ -321,13 +321,13 @@ def _populate_sub_parser_by_class(
321321
id_attr=cls._id_attr.replace("_","-")
322322
sub_parser_action.add_argument(f"--{id_attr}",required=True)
323323

324-
required,optional,dummy=cli.custom_actions[name][action_name]
325-
forxinrequired:
324+
custom_action=cli.custom_actions[name][action_name]
325+
forxincustom_action.required:
326326
ifx!=cls._id_attr:
327327
sub_parser_action.add_argument(
328328
f"--{x.replace('_','-')}",required=True
329329
)
330-
forxinoptional:
330+
forxincustom_action.optional:
331331
ifx!=cls._id_attr:
332332
sub_parser_action.add_argument(
333333
f"--{x.replace('_','-')}",required=False
@@ -350,13 +350,13 @@ def _populate_sub_parser_by_class(
350350
)
351351
sub_parser_action.add_argument("--sudo",required=False)
352352

353-
required,optional,dummy=cli.custom_actions[name][action_name]
354-
forxinrequired:
353+
custom_action=cli.custom_actions[name][action_name]
354+
forxincustom_action.required:
355355
ifx!=cls._id_attr:
356356
sub_parser_action.add_argument(
357357
f"--{x.replace('_','-')}",required=True
358358
)
359-
forxinoptional:
359+
forxincustom_action.optional:
360360
ifx!=cls._id_attr:
361361
sub_parser_action.add_argument(
362362
f"--{x.replace('_','-')}",required=False

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp