Delete checkHelpFunc

This commit is contained in:
Albert Nigmatzianov 2017-04-23 09:17:44 +02:00
parent 10f6b9d7e1
commit 681a777b18

View File

@ -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.