diff --git a/CHANGES/602.bugfix b/CHANGES/602.bugfix new file mode 100644 index 000000000..d5fc3e5e5 --- /dev/null +++ b/CHANGES/602.bugfix @@ -0,0 +1 @@ +Deprecated `--fields` and `--exclude-fields` on `pulp ansible content list` in favor of `--[exclude-]field`. diff --git a/pulpcore/cli/ansible/content.py b/pulpcore/cli/ansible/content.py index 47a65319b..20ef9e674 100644 --- a/pulpcore/cli/ansible/content.py +++ b/pulpcore/cli/ansible/content.py @@ -1,4 +1,4 @@ -from typing import IO, Any, Optional, Union +from typing import IO, Any, Callable, Optional, Union import click @@ -46,6 +46,40 @@ def _content_callback(ctx: click.Context, param: click.Parameter, value: Any) -> return value +def _fields_callback(ctx: click.Context, param: click.Parameter, value: Any) -> Any: + if value: + click.echo(_("Option {name} is deprecated.").format(name=param.opts[0]), err=True) + value = tuple(value.split(",")) + print(value) + + return value + + +def _list_command_wrapper(list_command: click.Command) -> click.Command: + assert list_command.callback is not None + _old_callback: Callable[[Any], Any] = list_command.callback + + def _new_callback(*args: Any, **kwargs: Any) -> Any: + _fields = kwargs.pop("_fields") + if _fields: + kwargs["fields"] += _fields + _exclude_fields = kwargs.pop("_exclude_fields") + if _exclude_fields: + kwargs["exclude_fields"] += _exclude_fields + + if not kwargs["fields"] and not kwargs["exclude_fields"]: + kwargs["exclude_fields"] = ( + "files", + "manifest", + "docs_blob", + ) + + return _old_callback(*args, **kwargs) + + list_command.callback = _new_callback + return list_command + + repository_option = resource_option( "--repository", default_plugin="ansible", @@ -119,12 +153,20 @@ def content(ctx: click.Context, pulp_ctx: PulpContext, content_type: str) -> Non ), ] +# Deprecated fields options + fields_options = [ - pulp_option("--fields", help=_("String list of fields to include in the result")), + pulp_option( + "--fields", + "_fields", + help=_("String list of fields to include in the result [DEPRECATED]"), + callback=_fields_callback, + ), pulp_option( "--exclude-fields", - default="files,manifest,docs_blob", - help=_("String list of fields to exclude from result"), + "_exclude_fields", + help=_("String list of fields to exclude from result [DEPRECATED]"), + callback=_fields_callback, ), ] @@ -175,7 +217,7 @@ def content(ctx: click.Context, pulp_ctx: PulpContext, content_type: str) -> Non href_option, ] -content.add_command(list_command(decorators=list_options + fields_options)) +content.add_command(_list_command_wrapper(list_command(decorators=list_options + fields_options))) content.add_command(show_command(decorators=lookup_options))