From 4c6bab5f5005335db37ceac3c30b5a40b8097559 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Fri, 14 Aug 2015 15:00:48 -0700 Subject: [PATCH] Fix ignore `-q` flag in `docker ps` when there is a default format. Docker ps default format should not take precedence over cli flags. This happens effectively for other flags except `-q`. We need to let the cli to set the format as table to print the expected output with `-q`. Signed-off-by: David Calavera Upstream-commit: df46bfdd4d28dcab432b2fc6c36131ff95223148 Component: engine --- components/engine/api/client/ps.go | 2 +- .../integration-cli/docker_cli_ps_test.go | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/components/engine/api/client/ps.go b/components/engine/api/client/ps.go index e7fb97c315..88ca1ee671 100644 --- a/components/engine/api/client/ps.go +++ b/components/engine/api/client/ps.go @@ -95,7 +95,7 @@ func (cli *DockerCli) CmdPs(args ...string) error { f := *format if len(f) == 0 { - if len(cli.PsFormat()) > 0 { + if len(cli.PsFormat()) > 0 && !*quiet { f = cli.PsFormat() } else { f = "table" diff --git a/components/engine/integration-cli/docker_cli_ps_test.go b/components/engine/integration-cli/docker_cli_ps_test.go index f0f63cb36c..30b0c0ce82 100644 --- a/components/engine/integration-cli/docker_cli_ps_test.go +++ b/components/engine/integration-cli/docker_cli_ps_test.go @@ -2,7 +2,10 @@ package main import ( "fmt" + "io/ioutil" + "os" "os/exec" + "path/filepath" "reflect" "strconv" "strings" @@ -554,3 +557,23 @@ func (s *DockerSuite) TestPsFormatHeaders(c *check.C) { c.Fatalf(`Expected 'NAMES\ntest\n', got %v`, out) } } + +func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) { + config := `{ + "psFormat": "{{ .ID }} default" +}` + d, err := ioutil.TempDir("", "integration-cli-") + c.Assert(err, check.IsNil) + defer os.RemoveAll(d) + + err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644) + c.Assert(err, check.IsNil) + + out, _ := dockerCmd(c, "run", "--name=test", "-d", "busybox", "top") + id := strings.TrimSpace(out) + + out, _ = dockerCmd(c, "--config", d, "ps", "-q") + if !strings.HasPrefix(id, strings.TrimSpace(out)) { + c.Fatalf("Expected to print only the container id, got %v\n", out) + } +}