diff --git a/cobra.go b/cobra.go index 78b92b0a..ea2784da 100644 --- a/cobra.go +++ b/cobra.go @@ -34,6 +34,15 @@ var EnablePrefixMatching bool = false // enables an information splash screen on Windows if the CLI is started from explorer.exe. var EnableWindowsMouseTrap bool = true +// HelpFlagShorthand is the character used to for the help flag's shorthand notation. The +// default value is "h". +var HelpFlagShorthand string = "h" + +// HelpFlagUsageFormatString is the format string used with fmt.Sprintf to produce the +// usage value for the help flag. The name of a given command is substituted in the +// formatted result. +var HelpFlagUsageFormatString string = "help for %s" + var MousetrapHelpText string = `This is a command line tool You need to open cmd.exe and run it from there. diff --git a/command.go b/command.go index cbbc3264..cbadbb96 100644 --- a/command.go +++ b/command.go @@ -859,7 +859,9 @@ func (c *Command) Flags() *flag.FlagSet { c.flagErrorBuf = new(bytes.Buffer) } c.flags.SetOutput(c.flagErrorBuf) - c.PersistentFlags().BoolVarP(&c.helpFlagVal, "help", "h", false, "help for "+c.Name()) + c.PersistentFlags().BoolVarP(&c.helpFlagVal, "help", + HelpFlagShorthand, false, + fmt.Sprintf(HelpFlagUsageFormatString, c.Name())) } return c.flags }