-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[23.0 backport] docker ps: always use --quiet, also combined with --format #4201
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
[23.0 backport] docker ps: always use --quiet, also combined with --format #4201
Conversation
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>
(cherry picked from commit f522905)
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>
(cherry picked from commit 37e02ff)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 23.0 #4201 +/- ##
=======================================
Coverage 58.83% 58.84%
=======================================
Files 572 572
Lines 49610 49620 +10
=======================================
+ Hits 29188 29198 +10
Misses 18648 18648
Partials 1774 1774 |
|
Discussing with @neersighted whether or not to backport this to v23.0; 👍 fixes /cc @tianon @vvoland @cpuguy83 @AkihiroSuda WDYT? |
|
No strong feelings - I don't think it needs a backport, but I think the new behavior is much more correct (and matches the user expectation better), so it's totally reasonable to backport if 23.x is going to continue to live for a while. |
|
FWIW; I discussed with @neersighted and he was okay with this change, but wanted to have a quick peek from others |
|
For v23, it might be safer to just retain the old behavior but print a warning message |
|
Yeah, I guess the "complicated" one is the case where both as passed through I could consider adding a commit that only changes the behaviour for |
docker ps -qdoes not work if the config file contains apsFormat#4093Previously, 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
--formatwas passed on the command-line.
This is a change in behavior, so may need some discussion; possible alternatives;
--formatand--quietare passedBefore this patch:
With this patch applied:
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:
The warning is printed on STDERR, so can be redirected:
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:
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)