diff --git a/command.go b/command.go index 5ffd20b..f753f37 100644 --- a/command.go +++ b/command.go @@ -1978,7 +1978,7 @@ func defaultUsageFunc(w io.Writer, in interface{}) error { fmt.Fprintf(w, "\n\nAdditional help topcis:") for _, subcmd := range c.Commands() { if subcmd.IsAdditionalHelpTopicCommand() { - fmt.Fprintf(w, "\n %s %s", rpad(subcmd.CommandPath(), subcmd.CommandPathPadding()), subcmd.Short) + fmt.Fprintf(w, "\n %s %s", rpad(subcmd.CommandPath(), subcmd.CommandPathPadding()), subcmd.Short) } } } diff --git a/completions.go b/completions.go index f7be8c7..cd899c7 100644 --- a/completions.go +++ b/completions.go @@ -555,7 +555,7 @@ func helpOrVersionFlagPresent(cmd *Command) bool { len(versionFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && versionFlag.Changed { return true } - if helpFlag := cmd.Flags().Lookup("help"); helpFlag != nil && + if helpFlag := cmd.Flags().Lookup(helpFlagName); helpFlag != nil && len(helpFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && helpFlag.Changed { return true } diff --git a/site/content/user_guide.md b/site/content/user_guide.md index 01cef7c..3f61882 100644 --- a/site/content/user_guide.md +++ b/site/content/user_guide.md @@ -552,7 +552,9 @@ cmd.SetHelpFunc(f func(*Command, []string)) cmd.SetHelpTemplate(s string) ``` -The latter two will also apply to any children commands. Templates specified with SetHelpTemplate are evaluated using +The latter two will also apply to any children commands. + +Note that templates specified with `SetHelpTemplate` are evaluated using `text/template` which can increase the size of the compiled executable. ## Usage Message @@ -587,6 +589,7 @@ Use "cobra [command] --help" for more information about a command. ``` ### Defining your own usage + You can provide your own usage function or template for Cobra to use. Like help, the function and template are overridable through public methods: @@ -595,6 +598,9 @@ cmd.SetUsageFunc(f func(*Command) error) cmd.SetUsageTemplate(s string) ``` +Note that templates specified with `SetUsageTemplate` are evaluated using +`text/template` which can increase the size of the compiled executable. + ## Version Flag Cobra adds a top-level '--version' flag if the Version field is set on the root command. @@ -602,6 +608,9 @@ Running an application with the '--version' flag will print the version to stdou the version template. The template can be customized using the `cmd.SetVersionTemplate(s string)` function. +Note that templates specified with `SetVersionTemplate` are evaluated using +`text/template` which can increase the size of the compiled executable. + ## Error Message Prefix Cobra prints an error message when receiving a non-nil error value.