From 681a777b18d132e530fd4f9f65fb6b29388bf08d Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Sun, 23 Apr 2017 09:17:44 +0200 Subject: [PATCH] Delete checkHelpFunc --- command.go | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/command.go b/command.go index 329bbeae..e51e70f0 100644 --- a/command.go +++ b/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.