mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
parent
6ed17b5128
commit
867d414548
1 changed files with 8 additions and 1 deletions
|
@ -721,7 +721,13 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
|||
func (c *Command) initHelpFlag() {
|
||||
c.mergePersistentFlags()
|
||||
if c.Flags().Lookup("help") == nil {
|
||||
c.Flags().BoolP("help", "h", false, "help for "+c.Name())
|
||||
usage := "help for "
|
||||
if c.Name() == "" {
|
||||
usage += "this command"
|
||||
} else {
|
||||
usage += c.Name()
|
||||
}
|
||||
c.Flags().BoolP("help", "h", false, usage)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -745,6 +751,7 @@ func (c *Command) initHelpCmd() {
|
|||
c.Printf("Unknown help topic %#q\n", args)
|
||||
c.Root().Usage()
|
||||
} else {
|
||||
cmd.initHelpFlag() // make possible 'help' flag to be shown
|
||||
cmd.Help()
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue