Skip to content

docker ps: always use --quiet, also combined with --format - #3666

Merged
thaJeztah merged 2 commits into
docker:masterfrom
thaJeztah:ps_always_accept_quiet
Apr 13, 2023
Merged

docker ps: always use --quiet, also combined with --format#3666
thaJeztah merged 2 commits into
docker:masterfrom
thaJeztah:ps_always_accept_quiet

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Jun 7, 2022

Copy link
Copy Markdown
Member

Previously, the formatter would ignore the quiet option if a custom format
was passed; this situation was handled in runPs(), where custom formats
would only be applied if the quiet option was not set, but only if the
format was set in the CLI's config.

This patch updates NewContainerFormat() to do the same, even if a --format
was passed on the command-line.

This is a change in behavior, so may need some discussion; possible alternatives;

  • produce an error if both --format and --quiet are passed
  • print a warning if both are passed (but use the logic from this patch)

Before this patch:

docker ps --format '{{.Image}}'ubuntu:22.04alpinedocker ps --format '{{.Image}}' --quietubuntu:22.04alpinemkdir -p ~/.docker/echo '{"psFormat": "{{.Image}}" > ~/.docker/config.jsondocker psubuntu:22.04alpinedocker ps --quietubuntu:22.04alpine

With this patch applied:

docker ps --format '{{.Image}}'ubuntu:22.04alpinedocker ps --format '{{.Image}}' --quiet40111f61d5c5482efdf39facmkdir -p ~/.docker/echo '{"psFormat": "{{.Image}}" > ~/.docker/config.jsondocker psubuntu:22.04alpinedocker ps --quiet40111f61d5c5482efdf39fac

docker ps: print warning if both --format and --quiet are set

Of both "--quiet" and "--format" are set, --quiet takes precedence. This
patch adds a warning to inform the user that their custom format is not
used:

docker ps --format='{{.Image}}'
ubuntu:22.04
alpine
docker ps --format='{{.Image}}' --quiet
WARNING: Ignoring custom format, because both --format and --quiet are set.
40111f61d5c5
482efdf39fac

The warning is printed on STDERR, so can be redirected:

docker ps --format='{{.Image}}' --quiet 2> /dev/null
40111f61d5c5
482efdf39fac

The warning is only shown if the format is set using the "--format" option.
No warning is shown if a custom format is set through the CLI configuration
file:

mkdir -p ~/.docker/
echo '{"psFormat": "{{.Image}}"}' > ~/.docker/config.json
docker ps
ubuntu:22.04
alpine
docker ps --quiet
40111f61d5c5
482efdf39fac

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter

codecov-commenter commented Jun 7, 2022

Copy link
Copy Markdown

Codecov Report

Merging #3666 (37e02ff) into master (d49b8ff) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@ Coverage Diff @@## master #3666 +/- ##
=======================================
Coverage 59.03% 59.04% =======================================
Files 288 288 Lines 24776 24781 +5 =======================================
+ Hits 14627 14632 +5 
Misses 9265 9265 Partials 884 884 

@thaJeztah
thaJeztahforce-pushed the ps_always_accept_quiet branch from 0cceced to cbfd0a2CompareDecember 5, 2022 16:21
@thaJeztah
thaJeztahforce-pushed the ps_always_accept_quiet branch from cbfd0a2 to d2dd896CompareJanuary 7, 2023 09:40
@thaJeztahthaJeztah added this to the 24.0.0 milestone Apr 9, 2023
@thaJeztahthaJeztah changed the title [rfc] docker ps: always use --quiet, also combined with --formatdocker ps: always use --quiet, also combined with --formatApr 9, 2023
Previously, the formatter would ignore the quiet option if a custom format
was passed; this situation was handled in runPs(), where custom formats
would only be applied if the quiet option was not set, but only if the
format was set in the CLI's config.
This patch updates NewContainerFormat() to do the same, even if a `--format`
was passed on the command-line.
This is a change in behavior, so may need some discussion; possible alternatives;
- produce an error if both `--format` and `--quiet` are passed
- print a warning if both are passed (but use the logic from this patch)
Before this patch:
```console
docker ps --format '{{.Image}}'
ubuntu:22.04
alpine
docker ps --format '{{.Image}}' --quiet
ubuntu:22.04
alpine
mkdir -p ~/.docker/
echo '{"psFormat": "{{.Image}}"}' > ~/.docker/config.json
docker ps
ubuntu:22.04
alpine
docker ps --quiet
ubuntu:22.04
alpine
```
With this patch applied:
```console
docker ps --format '{{.Image}}'
ubuntu:22.04
alpine
docker ps --format '{{.Image}}' --quiet
40111f61d5c5
482efdf39fac
mkdir -p ~/.docker/
echo '{"psFormat": "{{.Image}}"}' > ~/.docker/config.json
docker ps
ubuntu:22.04
alpine
docker ps --quiet
40111f61d5c5
482efdf39fac
```
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Of both "--quiet" and "--format" are set, --quiet takes precedence. This
patch adds a warning to inform the user that their custom format is not
used:
docker ps --format='{{.Image}}'
ubuntu:22.04
alpine
docker ps --format='{{.Image}}' --quiet
WARNING: Ignoring custom format, because both --format and --quiet are set.
40111f61d5c5
482efdf39fac
The warning is printed on STDERR, so can be redirected:
docker ps --format='{{.Image}}' --quiet 2> /dev/null
40111f61d5c5
482efdf39fac
The warning is only shown if the format is set using the "--format" option.
No warning is shown if a custom format is set through the CLI configuration
file:
mkdir -p ~/.docker/
echo '{"psFormat": "{{.Image}}"}' > ~/.docker/config.json
docker ps
ubuntu:22.04
alpine
docker ps --quiet
40111f61d5c5
482efdf39fac
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

@vvoland@rumpl@laurazard PTAL (I added the warning we discussed during one of our triage sessions)

@thaJeztah

Copy link
Copy Markdown
MemberAuthor

Thx! Let me bring this one in 👍

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker ps -q does not work if the config file contains a psFormat

4 participants

@thaJeztah@codecov-commenter@vdemeester@vvoland