Commit 20373525 authored by John L. Villalovos's avatar John L. Villalovos Committed by John Villalovos
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.
parent 61d86792
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ class CustomAction:
    required: Tuple[str, ...]
    optional: Tuple[str, ...]
    in_object: bool
    requires_id: bool  # if the `_id_attr` value should be a required argument


# custom_actions = {
@@ -86,6 +87,7 @@ def register_custom_action(
    required: Tuple[str, ...] = (),
    optional: Tuple[str, ...] = (),
    custom_action: Optional[str] = None,
    requires_id: bool = True,  # if the `_id_attr` value should be a required argument
) -> Callable[[__F], __F]:
    def wrap(f: __F) -> __F:
        @functools.wraps(f)
@@ -109,7 +111,10 @@ def register_custom_action(

            action = custom_action or f.__name__.replace("_", "-")
            custom_actions[final_name][action] = CustomAction(
                required=required, optional=optional, in_object=in_obj
                required=required,
                optional=optional,
                in_object=in_obj,
                requires_id=requires_id,
            )

        return cast(__F, wrapped_f)
+2 −2
Original line number Diff line number Diff line
@@ -315,13 +315,13 @@ def _populate_sub_parser_by_class(
                    )
                sub_parser_action.add_argument("--sudo", required=False)

            custom_action = cli.custom_actions[name][action_name]
            # We need to get the object somehow
            if not issubclass(cls, gitlab.mixins.GetWithoutIdMixin):
                if cls._id_attr is not None:
                if cls._id_attr is not None and custom_action.requires_id:
                    id_attr = cls._id_attr.replace("_", "-")
                    sub_parser_action.add_argument(f"--{id_attr}", required=True)

            custom_action = cli.custom_actions[name][action_name]
            for x in custom_action.required:
                if x != cls._id_attr:
                    sub_parser_action.add_argument(