зеркало из https://github.com/microsoft/docker.git
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:
Родитель
9fdb626bfb
Коммит
87255b6721
|
@ -32,7 +32,7 @@ func (cli *DockerCli) CmdVolume(args ...string) error {
|
||||||
description += fmt.Sprintf(" %-25.25s%s\n", cmd[0], cmd[1])
|
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 := Cli.Subcmd("volume", []string{"[COMMAND]"}, description, true)
|
||||||
cmd.Require(flag.Exact, 0)
|
cmd.Require(flag.Exact, 0)
|
||||||
cmd.ParseFlags(args, true)
|
cmd.ParseFlags(args, true)
|
||||||
|
@ -103,14 +103,15 @@ func (cli *DockerCli) CmdVolumeLs(args ...string) error {
|
||||||
// Usage: docker volume inspect [OPTIONS] VOLUME [VOLUME...]
|
// Usage: docker volume inspect [OPTIONS] VOLUME [VOLUME...]
|
||||||
func (cli *DockerCli) CmdVolumeInspect(args ...string) error {
|
func (cli *DockerCli) CmdVolumeInspect(args ...string) error {
|
||||||
cmd := Cli.Subcmd("volume inspect", []string{"VOLUME [VOLUME...]"}, "Return low-level information on a volume", true)
|
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.")
|
tmplStr := cmd.String([]string{"f", "-format"}, "", "Format the output using the given go template")
|
||||||
if err := cmd.Parse(args); err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.Require(flag.Min, 1)
|
cmd.Require(flag.Min, 1)
|
||||||
cmd.ParseFlags(args, true)
|
cmd.ParseFlags(args, true)
|
||||||
|
|
||||||
|
if err := cmd.Parse(args); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var tmpl *template.Template
|
var tmpl *template.Template
|
||||||
if *tmplStr != "" {
|
if *tmplStr != "" {
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -101,9 +101,10 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
|
||||||
// Skip first line
|
// Skip first line
|
||||||
helpOut = helpOut[1:]
|
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
|
// Stop on blank line or non-idented line
|
||||||
if cmd == "" || !unicode.IsSpace(rune(cmd[0])) {
|
if cmd == "" || !unicode.IsSpace(rune(cmd[0])) {
|
||||||
break
|
break
|
||||||
|
@ -111,10 +112,25 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
|
||||||
|
|
||||||
// Grab just the first word of each line
|
// Grab just the first word of each line
|
||||||
cmd = strings.Split(strings.TrimSpace(cmd), " ")[0]
|
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
|
// Check the full usage text
|
||||||
helpCmd := exec.Command(dockerBinary, cmd, "--help")
|
helpCmd := exec.Command(dockerBinary, args...)
|
||||||
helpCmd.Env = newEnvs
|
helpCmd.Env = newEnvs
|
||||||
out, stderr, ec, err = runCommandWithStdoutStderr(helpCmd)
|
out, stderr, ec, err = runCommandWithStdoutStderr(helpCmd)
|
||||||
if len(stderr) != 0 {
|
if len(stderr) != 0 {
|
||||||
|
@ -168,7 +184,9 @@ func (s *DockerSuite) TestHelpTextVerify(c *check.C) {
|
||||||
|
|
||||||
// For each command make sure we generate an error
|
// For each command make sure we generate an error
|
||||||
// if we give a bad arg
|
// 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)
|
out, stderr, ec, err = runCommandWithStdoutStderr(dCmd)
|
||||||
if len(out) != 0 || len(stderr) == 0 || ec == 0 || err == nil {
|
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)
|
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
|
ec = 0
|
||||||
if _, ok := skipNoArgs[cmd]; !ok {
|
if _, ok := skipNoArgs[cmd]; !ok {
|
||||||
args = []string{cmd}
|
args = strings.Split(cmd, " ")
|
||||||
dCmd = exec.Command(dockerBinary, args...)
|
dCmd = exec.Command(dockerBinary, args...)
|
||||||
stdout, stderr, ec, err = runCommandWithStdoutStderr(dCmd)
|
stdout, stderr, ec, err = runCommandWithStdoutStderr(dCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If its ok w/o any args then try again with an arg
|
// If its ok w/o any args then try again with an arg
|
||||||
if ec == 0 {
|
if ec == 0 {
|
||||||
args = []string{cmd, "badArg"}
|
args = strings.Split(cmd+" badArg", " ")
|
||||||
dCmd = exec.Command(dockerBinary, args...)
|
dCmd = exec.Command(dockerBinary, args...)
|
||||||
stdout, stderr, ec, err = runCommandWithStdoutStderr(dCmd)
|
stdout, stderr, ec, err = runCommandWithStdoutStderr(dCmd)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче