mirror of
https://github.com/spf13/cobra
synced 2025-05-05 21:07:24 +00:00
parent
10f6b9d7e1
commit
fb5d3a2cac
1 changed files with 8 additions and 1 deletions
|
@ -735,7 +735,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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -759,6 +765,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…
Add table
Reference in a new issue