mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
Delete checkHelpFunc
This commit is contained in:
parent
10f6b9d7e1
commit
681a777b18
1 changed files with 7 additions and 19 deletions
26
command.go
26
command.go
|
@ -215,9 +215,8 @@ func (c *Command) UsageFunc() (f func(*Command) error) {
|
|||
if c.usageFunc != nil {
|
||||
return c.usageFunc
|
||||
}
|
||||
|
||||
if c.HasParent() {
|
||||
return c.parent.UsageFunc()
|
||||
return c.Parent().UsageFunc()
|
||||
}
|
||||
return func(c *Command) error {
|
||||
c.mergePersistentFlags()
|
||||
|
@ -239,10 +238,13 @@ func (c *Command) Usage() error {
|
|||
// HelpFunc returns either the function set by SetHelpFunc for this command
|
||||
// or a parent, or it returns a function with default help behavior.
|
||||
func (c *Command) HelpFunc() func(*Command, []string) {
|
||||
if helpFunc := c.checkHelpFunc(); helpFunc != nil {
|
||||
return helpFunc
|
||||
if c.helpFunc != nil {
|
||||
return c.helpFunc
|
||||
}
|
||||
return func(*Command, []string) {
|
||||
if c.HasParent() {
|
||||
return c.Parent().HelpFunc()
|
||||
}
|
||||
return func(c *Command, a []string) {
|
||||
c.mergePersistentFlags()
|
||||
err := tmpl(c.OutOrStdout(), c.HelpTemplate(), c)
|
||||
if err != nil {
|
||||
|
@ -251,20 +253,6 @@ func (c *Command) HelpFunc() func(*Command, []string) {
|
|||
}
|
||||
}
|
||||
|
||||
// checkHelpFunc checks if there is helpFunc in ancestors of c.
|
||||
func (c *Command) checkHelpFunc() func(*Command, []string) {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
if c.helpFunc != nil {
|
||||
return c.helpFunc
|
||||
}
|
||||
if c.HasParent() {
|
||||
return c.parent.checkHelpFunc()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Help puts out the help for the command.
|
||||
// Used when a user calls help [command].
|
||||
// Can be defined by user by overriding HelpFunc.
|
||||
|
|
Loading…
Reference in a new issue