mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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>
This commit is contained in:
parent
0137e3eda2
commit
2feebd95d3
2 changed files with 15 additions and 9 deletions
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
c.Assert(err, check.NotNil, check.Commentf(stderr))
|
||||
c.Assert(stderr, checker.Contains, usage)
|
||||
|
||||
expected := "Usage: docker volume [OPTIONS] [COMMAND]"
|
||||
c.Assert(strings.Contains(stderr, expected), check.Equals, true)
|
||||
// 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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue