Initialize help flag in initHelpCmd

Fix #302
This commit is contained in:
Albert Nigmatzianov 2017-04-20 22:16:25 +02:00
parent 6ed17b5128
commit 867d414548

View file

@ -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()
}
},