mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
Add setters for default help strings
This commit is contained in:
parent
fe5e611709
commit
e2570c90ff
2 changed files with 13 additions and 1 deletions
|
@ -524,13 +524,15 @@ around it. In fact, you can provide your own if you want.
|
||||||
|
|
||||||
### Defining your own help
|
### Defining your own help
|
||||||
|
|
||||||
You can provide your own Help command or your own template for the default command to use
|
You can provide your own Help command or your own template or help strings for the default command to use
|
||||||
with following functions:
|
with following functions:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
cmd.SetHelpCommand(cmd *Command)
|
cmd.SetHelpCommand(cmd *Command)
|
||||||
cmd.SetHelpFunc(f func(*Command, []string))
|
cmd.SetHelpFunc(f func(*Command, []string))
|
||||||
cmd.SetHelpTemplate(s string)
|
cmd.SetHelpTemplate(s string)
|
||||||
|
cmd.SetShortHelpString(s string)
|
||||||
|
cmd.SetLongHelpString(s string)
|
||||||
```
|
```
|
||||||
|
|
||||||
The latter two will also apply to any children commands.
|
The latter two will also apply to any children commands.
|
||||||
|
|
10
command.go
10
command.go
|
@ -240,6 +240,16 @@ func (c *Command) SetHelpTemplate(s string) {
|
||||||
c.helpTemplate = s
|
c.helpTemplate = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetShortHelpString sets short help string to be used. Application can use it to set custom short help string.
|
||||||
|
func (c *Command) SetShortHelpString(s string) {
|
||||||
|
c.helpCommand.Short = s
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLongHelpString sets long help string to be used. Application can use it to set custom long help string.
|
||||||
|
func (c *Command) SetLongHelpString(s string) {
|
||||||
|
c.helpCommand.Long = s
|
||||||
|
}
|
||||||
|
|
||||||
// SetVersionTemplate sets version template to be used. Application can use it to set custom template.
|
// SetVersionTemplate sets version template to be used. Application can use it to set custom template.
|
||||||
func (c *Command) SetVersionTemplate(s string) {
|
func (c *Command) SetVersionTemplate(s string) {
|
||||||
c.versionTemplate = s
|
c.versionTemplate = s
|
||||||
|
|
Loading…
Reference in a new issue