From 7fdbd90f8805736aa78156faf7e6f8fdd2384af7 Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Tue, 23 Dec 2014 11:16:23 -0800 Subject: [PATCH] Return usage on parseExec error. Docker-DCO-1.1-Signed-off-by: Jessica Frazelle (github: jfrazelle) --- api/client/commands.go | 1 + integration-cli/docker_cli_exec_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/api/client/commands.go b/api/client/commands.go index 487b0b6cfd..e666d43205 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -2589,6 +2589,7 @@ func (cli *DockerCli) CmdExec(args ...string) error { execConfig, err := runconfig.ParseExec(cmd, args) if err != nil { + cmd.Usage() return err } if execConfig.Container == "" { diff --git a/integration-cli/docker_cli_exec_test.go b/integration-cli/docker_cli_exec_test.go index 747ad4ff8c..a3a6a23620 100644 --- a/integration-cli/docker_cli_exec_test.go +++ b/integration-cli/docker_cli_exec_test.go @@ -351,3 +351,19 @@ func TestExecTtyWithoutStdin(t *testing.T) { logDone("exec - forbid piped stdin to tty enabled container") } + +func TestExecParseError(t *testing.T) { + defer deleteAllContainers() + + runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top") + if out, _, err := runCommandWithOutput(runCmd); err != nil { + t.Fatal(out, err) + } + + // Test normal (non-detached) case first + cmd := exec.Command(dockerBinary, "exec", "top") + if out, _, err := runCommandWithOutput(cmd); err == nil || !strings.Contains(out, "Usage:") { + t.Fatalf("Should have thrown error & given usage: %s", out) + } + logDone("exec - error on parseExec should return usage") +}