Browse Source

Merge pull request #15873 from cpuguy83/no_args_for_volume_subcmd

Fix `docker volume invalidarg` so it displays usage
David Calavera 9 years ago
parent
commit
754d81bd69
2 changed files with 14 additions and 0 deletions
  1. 1 0
      api/client/volume.go
  2. 13 0
      integration-cli/docker_cli_volume_test.go

+ 1 - 0
api/client/volume.go

@@ -34,6 +34,7 @@ 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)
 
 	return cli.CmdVolumeLs(args...)

+ 13 - 0
integration-cli/docker_cli_volume_test.go

@@ -88,3 +88,16 @@ func (s *DockerSuite) TestVolumeCliRm(c *check.C) {
 		check.Commentf("volume rm should fail with non-existant volume"),
 	)
 }
+
+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)
+
+	// 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)
+}