Merge pull request #3666 from thaJeztah/ps_always_accept_quiet

docker ps: always use --quiet, also combined with --format
This commit is contained in:
Sebastiaan van Stijn 2023-04-13 13:53:39 +02:00 committed by GitHub
commit 6416d810dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 5 deletions

View File

@ -120,6 +120,8 @@ func runPs(dockerCli command.Cli, options *psOptions) error {
if len(options.format) == 0 {
// load custom psFormat from CLI config (if any)
options.format = dockerCli.ConfigFile().PsFormat
} else if options.quiet {
_, _ = dockerCli.Err().Write([]byte("WARNING: Ignoring custom format, because both --format and --quiet are set.\n"))
}
listOptions, err := buildContainerListOptions(options)

View File

@ -309,8 +309,22 @@ func TestContainerListWithFormat(t *testing.T) {
}, nil
},
})
t.Run("with format", func(t *testing.T) {
cli.OutBuffer().Reset()
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}")
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
})
t.Run("with format and quiet", func(t *testing.T) {
cli.OutBuffer().Reset()
cmd := newListCommand(cli)
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
assert.Check(t, cmd.Flags().Set("quiet", "true"))
assert.NilError(t, cmd.Execute())
assert.Equal(t, cli.ErrBuffer().String(), "WARNING: Ignoring custom format, because both --format and --quiet are set.\n")
golden.Assert(t, cli.OutBuffer().String(), "container-list-quiet.golden")
})
}

View File

@ -0,0 +1,2 @@
container_id
container_id

View File

@ -55,6 +55,9 @@ ports: {{- pad .Ports 1 0}}
}
return Format(format)
default: // custom format
if quiet {
return DefaultQuietFormat
}
return Format(source)
}
}

View File

@ -163,7 +163,7 @@ containerID2 ubuntu "" 24 hours ago foobar_bar
},
{
Context{Format: NewContainerFormat("table {{.Image}}", true, false)},
"IMAGE\nubuntu\nubuntu\n",
"containerID1\ncontainerID2\n",
},
{
Context{Format: NewContainerFormat("table", true, false)},