mirror of
https://github.com/spf13/cobra
synced 2025-01-30 15:36:47 +00:00
Some minor cleanup
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
This commit is contained in:
parent
6585f26cec
commit
5d464d15bf
3 changed files with 12 additions and 3 deletions
|
@ -1978,7 +1978,7 @@ func defaultUsageFunc(w io.Writer, in interface{}) error {
|
||||||
fmt.Fprintf(w, "\n\nAdditional help topcis:")
|
fmt.Fprintf(w, "\n\nAdditional help topcis:")
|
||||||
for _, subcmd := range c.Commands() {
|
for _, subcmd := range c.Commands() {
|
||||||
if subcmd.IsAdditionalHelpTopicCommand() {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -555,7 +555,7 @@ func helpOrVersionFlagPresent(cmd *Command) bool {
|
||||||
len(versionFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && versionFlag.Changed {
|
len(versionFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && versionFlag.Changed {
|
||||||
return true
|
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 {
|
len(helpFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && helpFlag.Changed {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -552,7 +552,9 @@ cmd.SetHelpFunc(f func(*Command, []string))
|
||||||
cmd.SetHelpTemplate(s 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.
|
`text/template` which can increase the size of the compiled executable.
|
||||||
|
|
||||||
## Usage Message
|
## Usage Message
|
||||||
|
@ -587,6 +589,7 @@ Use "cobra [command] --help" for more information about a command.
|
||||||
```
|
```
|
||||||
|
|
||||||
### Defining your own usage
|
### Defining your own usage
|
||||||
|
|
||||||
You can provide your own usage function or template for Cobra to use.
|
You can provide your own usage function or template for Cobra to use.
|
||||||
Like help, the function and template are overridable through public methods:
|
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)
|
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
|
## Version Flag
|
||||||
|
|
||||||
Cobra adds a top-level '--version' flag if the Version field is set on the root command.
|
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
|
the version template. The template can be customized using the
|
||||||
`cmd.SetVersionTemplate(s string)` function.
|
`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
|
## Error Message Prefix
|
||||||
|
|
||||||
Cobra prints an error message when receiving a non-nil error value.
|
Cobra prints an error message when receiving a non-nil error value.
|
||||||
|
|
Loading…
Reference in a new issue