Add --help to "docker volume inspect --help" output

Closes #16146

While in there, modified the testing infrastructure for the help text
so that we can get commands with nested commands - like "volume".

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2015-09-08 14:19:27 -07:00
parent 9fdb626bfb
commit 87255b6721
2 changed files with 31 additions and 12 deletions

View file

@ -32,7 +32,7 @@ func (cli *DockerCli) CmdVolume(args ...string) error {
description += fmt.Sprintf(" %-25.25s%s\n", cmd[0], cmd[1])
}
description += "\nRun 'docker volume COMMAND --help' for more information on a command."
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)
@ -103,14 +103,15 @@ func (cli *DockerCli) CmdVolumeLs(args ...string) error {
// Usage: docker volume inspect [OPTIONS] VOLUME [VOLUME...]
func (cli *DockerCli) CmdVolumeInspect(args ...string) error {
cmd := Cli.Subcmd("volume inspect", []string{"VOLUME [VOLUME...]"}, "Return low-level information on a volume", true)
tmplStr := cmd.String([]string{"f", "-format"}, "", "Format the output using the given go template.")
if err := cmd.Parse(args); err != nil {
return nil
}
tmplStr := cmd.String([]string{"f", "-format"}, "", "Format the output using the given go template")
cmd.Require(flag.Min, 1)
cmd.ParseFlags(args, true)
if err := cmd.Parse(args); err != nil {
return nil
}
var tmpl *template.Template
if *tmplStr != "" {
var err error

View file

@ -101,9 +101,10 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
// Skip first line
helpOut = helpOut[1:]
}
for _, cmd := range helpOut {
var stderr string
// Create the list of commands we want to test
cmdsToTest := []string{}
for _, cmd := range helpOut {
// Stop on blank line or non-idented line
if cmd == "" || !unicode.IsSpace(rune(cmd[0])) {
break
@ -111,10 +112,25 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
// Grab just the first word of each line
cmd = strings.Split(strings.TrimSpace(cmd), " ")[0]
cmds = append(cmds, cmd)
cmds = append(cmds, cmd) // Saving count for later
cmdsToTest = append(cmdsToTest, cmd)
}
// Add some 'two word' commands - would be nice to automatically
// calculate this list - somehow
cmdsToTest = append(cmdsToTest, "volume create")
cmdsToTest = append(cmdsToTest, "volume inspect")
cmdsToTest = append(cmdsToTest, "volume ls")
cmdsToTest = append(cmdsToTest, "volume rm")
for _, cmd := range cmdsToTest {
var stderr string
args := strings.Split(cmd+" --help", " ")
// Check the full usage text
helpCmd := exec.Command(dockerBinary, cmd, "--help")
helpCmd := exec.Command(dockerBinary, args...)
helpCmd.Env = newEnvs
out, stderr, ec, err = runCommandWithStdoutStderr(helpCmd)
if len(stderr) != 0 {
@ -168,7 +184,9 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
// For each command make sure we generate an error
// if we give a bad arg
dCmd := exec.Command(dockerBinary, cmd, "--badArg")
args = strings.Split(cmd+" --badArg", " ")
dCmd := exec.Command(dockerBinary, args...)
out, stderr, ec, err = runCommandWithStdoutStderr(dCmd)
if len(out) != 0 || len(stderr) == 0 || ec == 0 || err == nil {
c.Fatalf("Bad results from 'docker %s --badArg'\nec:%d\nstdout:%s\nstderr:%s\nerr:%q", cmd, ec, out, stderr, err)
@ -209,14 +227,14 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
ec = 0
if _, ok := skipNoArgs[cmd]; !ok {
args = []string{cmd}
args = strings.Split(cmd, " ")
dCmd = exec.Command(dockerBinary, args...)
stdout, stderr, ec, err = runCommandWithStdoutStderr(dCmd)
}
// If its ok w/o any args then try again with an arg
if ec == 0 {
args = []string{cmd, "badArg"}
args = strings.Split(cmd+" badArg", " ")
dCmd = exec.Command(dockerBinary, args...)
stdout, stderr, ec, err = runCommandWithStdoutStderr(dCmd)
}