Skip to content

Commit

Permalink
Add json output for images subcommand (#1433)
Browse files Browse the repository at this point in the history
* Add json output for images subcommand

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bradley A. Thornton <bthornto@redhat.com>
  • Loading branch information
3 people authored Mar 21, 2023
1 parent 2caa4a1 commit 3bb80cc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
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

0 comments on commit 3bb80cc

Please sign in to comment.