mirror of https://github.com/docker/cli.git
Support usage messages on bad flags.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
13cea4e58d
commit
11ede59379
|
@ -1,6 +1,8 @@
|
||||||
package cobraadaptor
|
package cobraadaptor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/api/client"
|
"github.com/docker/docker/api/client"
|
||||||
"github.com/docker/docker/api/client/volume"
|
"github.com/docker/docker/api/client/volume"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
|
@ -28,6 +30,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
|
||||||
}
|
}
|
||||||
rootCmd.SetUsageTemplate(usageTemplate)
|
rootCmd.SetUsageTemplate(usageTemplate)
|
||||||
rootCmd.SetHelpTemplate(helpTemplate)
|
rootCmd.SetHelpTemplate(helpTemplate)
|
||||||
|
rootCmd.SetFlagErrorFunc(flagErrorFunc)
|
||||||
rootCmd.SetOutput(stdout)
|
rootCmd.SetOutput(stdout)
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
volume.NewVolumeCommand(dockerCli),
|
volume.NewVolumeCommand(dockerCli),
|
||||||
|
@ -68,6 +71,20 @@ func (c CobraAdaptor) Command(name string) func(...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// flagErrorFunc prints an error messages which matches the format of the
|
||||||
|
// docker/docker/cli error messages
|
||||||
|
func flagErrorFunc(cmd *cobra.Command, err error) error {
|
||||||
|
if err == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
usage := ""
|
||||||
|
if cmd.HasSubCommands() {
|
||||||
|
usage = "\n\n" + cmd.UsageString()
|
||||||
|
}
|
||||||
|
return fmt.Errorf("%s\nSee '%s --help'.%s", err, cmd.CommandPath(), usage)
|
||||||
|
}
|
||||||
|
|
||||||
var usageTemplate = `Usage: {{if not .HasSubCommands}}{{if .HasLocalFlags}}{{appendIfNotPresent .UseLine "[OPTIONS]"}}{{else}}{{.UseLine}}{{end}}{{end}}{{if .HasSubCommands}}{{ .CommandPath}} COMMAND{{end}}
|
var usageTemplate = `Usage: {{if not .HasSubCommands}}{{if .HasLocalFlags}}{{appendIfNotPresent .UseLine "[OPTIONS]"}}{{else}}{{.UseLine}}{{end}}{{end}}{{if .HasSubCommands}}{{ .CommandPath}} COMMAND{{end}}
|
||||||
|
|
||||||
{{with or .Long .Short }}{{. | trim}}{{end}}{{if gt .Aliases 0}}
|
{{with or .Long .Short }}{{. | trim}}{{end}}{{if gt .Aliases 0}}
|
||||||
|
|
Loading…
Reference in New Issue