Don't automagically add "[OPTIONS]" to usage

This removes the logic to automatically
add [OPTIONS] to the usage output.

The current logic was broken if a command
only has deprecated or hidden flags, and
in many cases put the [OPTIONS] in the
wrong location.

Requiring the usage string to be set
manually gives more predictable results,
and shouldn't require much to maintain.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2016-07-16 16:44:10 +02:00
parent 5545165e02
commit 6393b5fcc7
2 changed files with 3 additions and 8 deletions

7
cli.go
View File

@ -155,11 +155,6 @@ func Subcmd(name string, synopses []string, description string, exitOnError bool
} }
flags.ShortUsage = func() { flags.ShortUsage = func() {
options := ""
if flags.FlagCountUndeprecated() > 0 {
options = " [OPTIONS]"
}
if len(synopses) == 0 { if len(synopses) == 0 {
synopses = []string{""} synopses = []string{""}
} }
@ -176,7 +171,7 @@ func Subcmd(name string, synopses []string, description string, exitOnError bool
synopsis = " " + synopsis synopsis = " " + synopsis
} }
fmt.Fprintf(flags.Out(), "\n%sdocker %s%s%s", lead, name, options, synopsis) fmt.Fprintf(flags.Out(), "\n%sdocker %s%s", lead, name, synopsis)
} }
fmt.Fprintf(flags.Out(), "\n\n%s\n", description) fmt.Fprintf(flags.Out(), "\n\n%s\n", description)

View File

@ -32,7 +32,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
dockerCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags) dockerCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags)
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "docker", Use: "docker [OPTIONS]",
SilenceUsage: true, SilenceUsage: true,
SilenceErrors: true, SilenceErrors: true,
} }
@ -131,7 +131,7 @@ func (c CobraAdaptor) Command(name string) func(...string) error {
return nil return nil
} }
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}}{{.UseLine}}{{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}}