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>
| ... | ... |
@@ -33,11 +33,12 @@ func (cli *DockerCli) CmdVolume(args ...string) error {
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
description += "\nRun 'docker volume COMMAND --help' for more information on a command" |
| 36 |
- cmd := Cli.Subcmd("volume", []string{"[COMMAND]"}, description, true)
|
|
| 37 |
- cmd.Require(flag.Exact, 0) |
|
| 38 |
- cmd.ParseFlags(args, true) |
|
| 36 |
+ cmd := Cli.Subcmd("volume", []string{"[COMMAND]"}, description, false)
|
|
| 39 | 37 |
|
| 40 |
- return cli.CmdVolumeLs(args...) |
|
| 38 |
+ cmd.Require(flag.Exact, 0) |
|
| 39 |
+ err := cmd.ParseFlags(args, true) |
|
| 40 |
+ cmd.Usage() |
|
| 41 |
+ return err |
|
| 41 | 42 |
} |
| 42 | 43 |
|
| 43 | 44 |
// CmdVolumeLs outputs a list of Docker volumes. |
| ... | ... |
@@ -130,13 +130,18 @@ func (s *DockerSuite) TestVolumeCliRm(c *check.C) {
|
| 130 | 130 |
|
| 131 | 131 |
func (s *DockerSuite) TestVolumeCliNoArgs(c *check.C) {
|
| 132 | 132 |
out, _ := dockerCmd(c, "volume") |
| 133 |
- // no args should produce the `volume ls` output |
|
| 134 |
- c.Assert(strings.Contains(out, "DRIVER"), check.Equals, true) |
|
| 133 |
+ // no args should produce the cmd usage output |
|
| 134 |
+ usage := "Usage: docker volume [OPTIONS] [COMMAND]" |
|
| 135 |
+ c.Assert(out, checker.Contains, usage) |
|
| 135 | 136 |
|
| 136 | 137 |
// invalid arg should error and show the command usage on stderr |
| 137 | 138 |
_, stderr, _, err := runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "somearg")) |
| 138 |
- c.Assert(err, check.NotNil) |
|
| 139 |
- |
|
| 140 |
- expected := "Usage: docker volume [OPTIONS] [COMMAND]" |
|
| 141 |
- c.Assert(strings.Contains(stderr, expected), check.Equals, true) |
|
| 139 |
+ c.Assert(err, check.NotNil, check.Commentf(stderr)) |
|
| 140 |
+ c.Assert(stderr, checker.Contains, usage) |
|
| 141 |
+ |
|
| 142 |
+ // invalid flag should error and show the flag error and cmd usage |
|
| 143 |
+ _, stderr, _, err = runCommandWithStdoutStderr(exec.Command(dockerBinary, "volume", "--no-such-flag")) |
|
| 144 |
+ c.Assert(err, check.NotNil, check.Commentf(stderr)) |
|
| 145 |
+ c.Assert(stderr, checker.Contains, usage) |
|
| 146 |
+ c.Assert(stderr, checker.Contains, "flag provided but not defined: --no-such-flag") |
|
| 142 | 147 |
} |