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

Commit2037352

Browse files
chore(cli): add ability to not add_id_attr as an argument
In some cases we don't want to have `_id_attr` as an argument.Add ability to have it not be added as an argument.
1 parent61d8679 commit2037352

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

‎gitlab/cli.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CustomAction:
3636
required:Tuple[str, ...]
3737
optional:Tuple[str, ...]
3838
in_object:bool
39+
requires_id:bool# if the `_id_attr` value should be a required argument
3940

4041

4142
# custom_actions = {
@@ -86,6 +87,7 @@ def register_custom_action(
8687
required:Tuple[str, ...]= (),
8788
optional:Tuple[str, ...]= (),
8889
custom_action:Optional[str]=None,
90+
requires_id:bool=True,# if the `_id_attr` value should be a required argument
8991
)->Callable[[__F],__F]:
9092
defwrap(f:__F)->__F:
9193
@functools.wraps(f)
@@ -109,7 +111,10 @@ def wrapped_f(*args: Any, **kwargs: Any) -> Any:
109111

110112
action=custom_actionorf.__name__.replace("_","-")
111113
custom_actions[final_name][action]=CustomAction(
112-
required=required,optional=optional,in_object=in_obj
114+
required=required,
115+
optional=optional,
116+
in_object=in_obj,
117+
requires_id=requires_id,
113118
)
114119

115120
returncast(__F,wrapped_f)

‎gitlab/v4/cli.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,13 @@ def _populate_sub_parser_by_class(
315315
)
316316
sub_parser_action.add_argument("--sudo",required=False)
317317

318+
custom_action=cli.custom_actions[name][action_name]
318319
# We need to get the object somehow
319320
ifnotissubclass(cls,gitlab.mixins.GetWithoutIdMixin):
320-
ifcls._id_attrisnotNone:
321+
ifcls._id_attrisnotNoneandcustom_action.requires_id:
321322
id_attr=cls._id_attr.replace("_","-")
322323
sub_parser_action.add_argument(f"--{id_attr}",required=True)
323324

324-
custom_action=cli.custom_actions[name][action_name]
325325
forxincustom_action.required:
326326
ifx!=cls._id_attr:
327327
sub_parser_action.add_argument(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp