Some minor cleanup

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
This commit is contained in:
Marc Khouzam 2025-01-25 08:16:50 -05:00
parent 6585f26cec
commit 5d464d15bf
3 changed files with 12 additions and 3 deletions

View file

@ -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
}

View file

@ -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.