mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
parent
ca5710c94e
commit
52ae6a1d02
1 changed files with 24 additions and 23 deletions
11
command.go
11
command.go
|
@ -700,7 +700,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
|
||||
|
||||
|
@ -764,9 +764,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
|
||||
}
|
||||
|
||||
|
@ -789,7 +791,6 @@ func (c *Command) initHelpCmd() {
|
|||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
c.RemoveCommand(c.helpCommand)
|
||||
c.AddCommand(c.helpCommand)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue