File tree 2 files changed +8
-3
lines changed
2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ class CustomAction:
36
36
required : Tuple [str , ...]
37
37
optional : Tuple [str , ...]
38
38
in_object : bool
39
+ requires_id : bool # if the `_id_attr` value should be a required argument
39
40
40
41
41
42
# custom_actions = {
@@ -86,6 +87,7 @@ def register_custom_action(
86
87
required : Tuple [str , ...] = (),
87
88
optional : Tuple [str , ...] = (),
88
89
custom_action : Optional [str ] = None ,
90
+ requires_id : bool = True , # if the `_id_attr` value should be a required argument
89
91
) -> Callable [[__F ], __F ]:
90
92
def wrap (f : __F ) -> __F :
91
93
@functools .wraps (f )
@@ -109,7 +111,10 @@ def wrapped_f(*args: Any, **kwargs: Any) -> Any:
109
111
110
112
action = custom_action or f .__name__ .replace ("_" , "-" )
111
113
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 ,
113
118
)
114
119
115
120
return cast (__F , wrapped_f )
Original file line number Diff line number Diff line change @@ -315,13 +315,13 @@ def _populate_sub_parser_by_class(
315
315
)
316
316
sub_parser_action .add_argument ("--sudo" , required = False )
317
317
318
+ custom_action = cli .custom_actions [name ][action_name ]
318
319
# We need to get the object somehow
319
320
if not issubclass (cls , gitlab .mixins .GetWithoutIdMixin ):
320
- if cls ._id_attr is not None :
321
+ if cls ._id_attr is not None and custom_action . requires_id :
321
322
id_attr = cls ._id_attr .replace ("_" , "-" )
322
323
sub_parser_action .add_argument (f"--{ id_attr } " , required = True )
323
324
324
- custom_action = cli .custom_actions [name ][action_name ]
325
325
for x in custom_action .required :
326
326
if x != cls ._id_attr :
327
327
sub_parser_action .add_argument (
You can’t perform that action at this time.
0 commit comments