Make initHelpCmd public

Useful for solving #424
This commit is contained in:
Albert Nigmatzianov 2017-05-08 08:27:34 +02:00
parent d83a1d7ccd
commit 5960650669

View file

@ -675,7 +675,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
// initialize help as the last point possible to allow for user
// overriding
c.initHelpCmd()
c.InitDefaultHelpCmd()
var args []string
@ -739,9 +739,11 @@ func (c *Command) InitDefaultHelpFlag() {
}
}
func (c *Command) initHelpCmd() {
if c.helpCommand == nil {
if !c.HasSubCommands() {
// InitDefaultHelpCmd adds default help command to c.
// It is called automatically by executing the c or by calling help and usage.
// If c already has help command or c has no subcommands, it will do nothing.
func (c *Command) InitDefaultHelpCmd() {
if c.helpCommand != nil || !c.HasSubCommands() {
return
}
@ -764,7 +766,6 @@ func (c *Command) initHelpCmd() {
}
},
}
}
c.RemoveCommand(c.helpCommand)
c.AddCommand(c.helpCommand)
}