mirror of https://github.com/docker/cli.git
Merge pull request #3666 from thaJeztah/ps_always_accept_quiet
docker ps: always use --quiet, also combined with --format
This commit is contained in:
commit
6416d810dc
|
@ -120,6 +120,8 @@ func runPs(dockerCli command.Cli, options *psOptions) error {
|
||||||
if len(options.format) == 0 {
|
if len(options.format) == 0 {
|
||||||
// load custom psFormat from CLI config (if any)
|
// load custom psFormat from CLI config (if any)
|
||||||
options.format = dockerCli.ConfigFile().PsFormat
|
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)
|
listOptions, err := buildContainerListOptions(options)
|
||||||
|
|
|
@ -309,8 +309,22 @@ func TestContainerListWithFormat(t *testing.T) {
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("with format", func(t *testing.T) {
|
||||||
|
cli.OutBuffer().Reset()
|
||||||
cmd := newListCommand(cli)
|
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())
|
assert.NilError(t, cmd.Execute())
|
||||||
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
|
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")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
container_id
|
||||||
|
container_id
|
|
@ -55,6 +55,9 @@ ports: {{- pad .Ports 1 0}}
|
||||||
}
|
}
|
||||||
return Format(format)
|
return Format(format)
|
||||||
default: // custom format
|
default: // custom format
|
||||||
|
if quiet {
|
||||||
|
return DefaultQuietFormat
|
||||||
|
}
|
||||||
return Format(source)
|
return Format(source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ containerID2 ubuntu "" 24 hours ago foobar_bar
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table {{.Image}}", true, false)},
|
Context{Format: NewContainerFormat("table {{.Image}}", true, false)},
|
||||||
"IMAGE\nubuntu\nubuntu\n",
|
"containerID1\ncontainerID2\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: NewContainerFormat("table", true, false)},
|
Context{Format: NewContainerFormat("table", true, false)},
|
||||||
|
|
Loading…
Reference in New Issue