Browse code

Return usage on parseExec error.

Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)

Jessica Frazelle authored on 2014/12/24 04:16:23
Showing 2 changed files
... ...
@@ -2589,6 +2589,7 @@ func (cli *DockerCli) CmdExec(args ...string) error {
2589 2589
 
2590 2590
 	execConfig, err := runconfig.ParseExec(cmd, args)
2591 2591
 	if err != nil {
2592
+		cmd.Usage()
2592 2593
 		return err
2593 2594
 	}
2594 2595
 	if execConfig.Container == "" {
... ...
@@ -351,3 +351,19 @@ func TestExecTtyWithoutStdin(t *testing.T) {
351 351
 
352 352
 	logDone("exec - forbid piped stdin to tty enabled container")
353 353
 }
354
+
355
+func TestExecParseError(t *testing.T) {
356
+	defer deleteAllContainers()
357
+
358
+	runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "top", "busybox", "top")
359
+	if out, _, err := runCommandWithOutput(runCmd); err != nil {
360
+		t.Fatal(out, err)
361
+	}
362
+
363
+	// Test normal (non-detached) case first
364
+	cmd := exec.Command(dockerBinary, "exec", "top")
365
+	if out, _, err := runCommandWithOutput(cmd); err == nil || !strings.Contains(out, "Usage:") {
366
+		t.Fatalf("Should have thrown error & given usage: %s", out)
367
+	}
368
+	logDone("exec - error on parseExec should return usage")
369
+}