Browse Source

Make `docker volume` behave like `docker network`

Before, typing `docker volume` with no args would forward to the handler
for `docker volume ls`, except the flags for the `ls` subcommand were
not supported.
Instead just print the cmd usage.

This makes the behavior of the `docker volume` subcommand behave exactly
like the `docker network` subcommand.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 9 years ago
parent
commit
2feebd95d3
2 changed files with 16 additions and 10 deletions
  1. 5 4
      api/client/volume.go
  2. 11 6
      integration-cli/docker_cli_volume_test.go

+ 5 - 4
api/client/volume.go

@@ -33,11 +33,12 @@ func (cli *DockerCli) CmdVolume(args ...string) error {
 	}
 
 	description += "\nRun 'docker volume COMMAND --help' for more information on a command"
-	cmd := Cli.Subcmd("volume", []string{"[COMMAND]"}, description, true)
-	cmd.Require(flag.Exact, 0)
-	cmd.ParseFlags(args, true)
+	cmd := Cli.Subcmd("volume", []string{"[COMMAND]"}, description, false)
 
-	return cli.CmdVolumeLs(args...)
+	cmd.Require(flag.Exact, 0)
+	err := cmd.ParseFlags(args, true)
+	cmd.Usage()
+	return err
 }
 
 // CmdVolumeLs outputs a list of Docker volumes.

+ 11 - 6
integration-cli/docker_cli_volume_test.go

@@ -130,13 +130,18 @@ func (s *DockerSuite) TestVolumeCliRm(c *check.C) {
 
 func (s *DockerSuite) TestVolumeCliNoArgs(c *check.C) {
 	out, _ := dockerCmd(c, "volume")
-	// no args should produce the `volume ls` output
-	c.Assert(strings.Contains(out, "DRIVER"), check.Equals, true)
+	// no args should produce the cmd usage output
+	usage := "Usage:	docker volume [OPTIONS] [COMMAND]"
+	c.Assert(out, checker.Contains, usage)
 
 	// invalid arg should error and show the command usage on stderr
 	_, stderr, _, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "somearg"))
-	c.Assert(err, check.NotNil)
-
-	expected := "Usage:	docker volume [OPTIONS] [COMMAND]"
-	c.Assert(strings.Contains(stderr, expected), check.Equals, true)
+	c.Assert(err, check.NotNil, check.Commentf(stderr))
+	c.Assert(stderr, checker.Contains, usage)
+
+	// invalid flag should error and show the flag error and cmd usage
+	_, stderr, _, err = runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "--no-such-flag"))
+	c.Assert(err, check.NotNil, check.Commentf(stderr))
+	c.Assert(stderr, checker.Contains, usage)
+	c.Assert(stderr, checker.Contains, "flag provided but not defined: --no-such-flag")
 }