Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json output for images subcommand #1433

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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$"
]
}
11 changes: 11 additions & 0 deletions tests/integration/actions/images/test_stdout_tmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down