瀏覽代碼

Return usage on parseExec error.

Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
Jessica Frazelle 10 年之前
父節點
當前提交
7fdbd90f88
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 1 0
      api/client/commands.go
  2. 16 0
      integration-cli/docker_cli_exec_test.go

+ 1 - 0
api/client/commands.go

@@ -2589,6 +2589,7 @@ func (cli *DockerCli) CmdExec(args ...string) error {
 
 
 	execConfig, err := runconfig.ParseExec(cmd, args)
 	execConfig, err := runconfig.ParseExec(cmd, args)
 	if err != nil {
 	if err != nil {
+		cmd.Usage()
 		return err
 		return err
 	}
 	}
 	if execConfig.Container == "" {
 	if execConfig.Container == "" {

+ 16 - 0
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")
 	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")
+}