mirror of
https://github.com/spf13/cobra
synced 2025-05-05 21:07:24 +00:00
parent
d83a1d7ccd
commit
5960650669
1 changed files with 24 additions and 23 deletions
11
command.go
11
command.go
|
@ -675,7 +675,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||||
|
|
||||||
// initialize help as the last point possible to allow for user
|
// initialize help as the last point possible to allow for user
|
||||||
// overriding
|
// overriding
|
||||||
c.initHelpCmd()
|
c.InitDefaultHelpCmd()
|
||||||
|
|
||||||
var args []string
|
var args []string
|
||||||
|
|
||||||
|
@ -739,9 +739,11 @@ func (c *Command) InitDefaultHelpFlag() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) initHelpCmd() {
|
// InitDefaultHelpCmd adds default help command to c.
|
||||||
if c.helpCommand == nil {
|
// It is called automatically by executing the c or by calling help and usage.
|
||||||
if !c.HasSubCommands() {
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -764,7 +766,6 @@ func (c *Command) initHelpCmd() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
|
||||||
c.RemoveCommand(c.helpCommand)
|
c.RemoveCommand(c.helpCommand)
|
||||||
c.AddCommand(c.helpCommand)
|
c.AddCommand(c.helpCommand)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue