diff --git a/src/ansible_navigator/actions/images.py b/src/ansible_navigator/actions/images.py index 6a89ab82d..8fc9abfb9 100644 --- a/src/ansible_navigator/actions/images.py +++ b/src/ansible_navigator/actions/images.py @@ -148,7 +148,7 @@ def run_stdout(self) -> RunStdoutReturn: filtered.append(filter_content_keys(image)) print_to_stdout( content=filtered, - content_format=ContentFormat.YAML, + content_format=getattr(ContentFormat, self._args.format.upper()), use_color=self._args.display_color, ) return RunStdoutReturn(message="", return_code=0) diff --git a/src/ansible_navigator/configuration_subsystem/navigator_configuration.py b/src/ansible_navigator/configuration_subsystem/navigator_configuration.py index 0e3e7ef12..53b7484ea 100644 --- a/src/ansible_navigator/configuration_subsystem/navigator_configuration.py +++ b/src/ansible_navigator/configuration_subsystem/navigator_configuration.py @@ -398,7 +398,7 @@ class Internals: choices=["json", "yaml"], cli_parameters=CliParameters(short="--fmt"), short_description="Specify the format for stdout output.", - subcommands=["collections"], + subcommands=["collections", "images"], value=SettingsEntryValue(default="yaml"), version_added="v2.3", ), diff --git a/tests/fixtures/integration/actions/images/test_stdout_tmux.py/test/4.json b/tests/fixtures/integration/actions/images/test_stdout_tmux.py/test/4.json new file mode 100644 index 000000000..c65252cc0 --- /dev/null +++ b/tests/fixtures/integration/actions/images/test_stdout_tmux.py/test/4.json @@ -0,0 +1,28 @@ +{ + "name": "test[clear-&&-ansible-navigator-images---ee-true---ll-debug---mode-stdout---format-json--|-grep-creator-print-image-details-as-json-output-['name:-creator-ee']-[]-true-4-search-for-help]", + "index": 4, + "comment": "print image details as json output", + "additional_information": { + "present": [ + "name: creator-ee" + ], + "absent": [], + "compared_fixture": false + }, + "output": [ + " full_name: ghcr.io/ansible/creator-ee:v0.13.0", + " org.opencontainers.image.source: https://github.com/ansible/creator-ee", + " created_by: '/bin/sh -c #(nop) LABEL org.opencontainers.image.source https://github.com/ansible/creator-ee/blob/main/base/Containerfile'", + " - comment: FROM creator-base", + " created_by: '/bin/sh -c #(nop) LABEL org.opencontainers.image.source https://github.com/ansible/creator-ee'", + " org.opencontainers.image.source: https://github.com/ansible/creator-ee", + " - ghcr.io/ansible/creator-ee:v0.13.0", + " - ghcr.io/ansible/creator-ee@sha256:341e9bee3198244600f7553a9844698717c208080eb6d32f42d4c223dcc0bcb0", + " - ghcr.io/ansible/creator-ee@sha256:b01b5f96fd07d1df1437fa34bef6dfeb960851c35e678243b5c730bfab9842ad", + " - ghcr.io/ansible/creator-ee:v0.13.0", + " name: creator-ee", + " name_tag: creator-ee:v0.13.0 (primary)", + " repository: ghcr.io/ansible/creator-ee", + "(venv) bash$" + ] +} diff --git a/tests/integration/actions/images/test_stdout_tmux.py b/tests/integration/actions/images/test_stdout_tmux.py index b8a9eae1f..4de0387bd 100644 --- a/tests/integration/actions/images/test_stdout_tmux.py +++ b/tests/integration/actions/images/test_stdout_tmux.py @@ -86,6 +86,17 @@ class ShellCommand(UiTestStep): "must be one or more of", ], ), + ShellCommand( + comment="print image details as json output", + user_input=StdoutCommand( + cmdline="", + mode="stdout", + format="json", + execution_environment=True, + raw_append=" | grep creator", + ).join(), + present=['"name": "creator-ee"'], + ), ) steps = add_indices(stdout_tests)