Skip to content

Commit 6416d81

Browse files
authored
Merge pull request #3666 from thaJeztah/ps_always_accept_quiet
docker ps: always use --quiet, also combined with --format
2 parents e4c6862 + 37e02ff commit 6416d81

5 files changed

Lines changed: 26 additions & 5 deletions

File tree

cli/command/container/list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ func runPs(dockerCli command.Cli, options *psOptions) error {
120120
if len(options.format) == 0 {
121121
// load custom psFormat from CLI config (if any)
122122
options.format = dockerCli.ConfigFile().PsFormat
123+
} else if options.quiet {
124+
_, _ = dockerCli.Err().Write([]byte("WARNING: Ignoring custom format, because both --format and --quiet are set.\n"))
123125
}
124126

125127
listOptions, err := buildContainerListOptions(options)

cli/command/container/list_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,22 @@ func TestContainerListWithFormat(t *testing.T) {
309309
}, nil
310310
},
311311
})
312-
cmd := newListCommand(cli)
313-
cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}")
314-
assert.NilError(t, cmd.Execute())
315-
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
312+
313+
t.Run("with format", func(t *testing.T) {
314+
cli.OutBuffer().Reset()
315+
cmd := newListCommand(cli)
316+
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
317+
assert.NilError(t, cmd.Execute())
318+
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
319+
})
320+
321+
t.Run("with format and quiet", func(t *testing.T) {
322+
cli.OutBuffer().Reset()
323+
cmd := newListCommand(cli)
324+
assert.Check(t, cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}"))
325+
assert.Check(t, cmd.Flags().Set("quiet", "true"))
326+
assert.NilError(t, cmd.Execute())
327+
assert.Equal(t, cli.ErrBuffer().String(), "WARNING: Ignoring custom format, because both --format and --quiet are set.\n")
328+
golden.Assert(t, cli.OutBuffer().String(), "container-list-quiet.golden")
329+
})
316330
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
container_id
2+
container_id

cli/command/formatter/container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ ports: {{- pad .Ports 1 0}}
5555
}
5656
return Format(format)
5757
default: // custom format
58+
if quiet {
59+
return DefaultQuietFormat
60+
}
5861
return Format(source)
5962
}
6063
}

cli/command/formatter/container_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ containerID2 ubuntu "" 24 hours ago foobar_bar
163163
},
164164
{
165165
Context{Format: NewContainerFormat("table {{.Image}}", true, false)},
166-
"IMAGE\nubuntu\nubuntu\n",
166+
"containerID1\ncontainerID2\n",
167167
},
168168
{
169169
Context{Format: NewContainerFormat("table", true, false)},

0 commit comments

Comments
 (0)