Skip to content
Myr

Merge pull request #353 from bogem/helpfunc

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix condition in HelpFunc

authored by Eric Paris · committed by GitHub · parents ec2fe78, 011f19e · Browse files · 1 file+16 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−6 removed

  • other:+16 added−6 removed

1 file+16 added−6 removed

modified:command.go+16 added-6 removed
229 unmodified lines
230231// HelpFunc returns either the function set by SetHelpFunc for this command232// or a parent, or it returns a function with default help behavior.233func (c *Command) HelpFunc() func(*Command, []string) {234 cmd := c235 for cmd != nil {236 if cmd.helpFunc != nil {237 return cmd.helpFunc234 if helpFunc := c.checkHelpFunc(); helpFunc != nil {235 return helpFunc238 }239 cmd = cmd.parent236 }237 return func(*Command, []string) {238 c.mergePersistentFlags()239 err := tmpl(c.OutOrStdout(), c.HelpTemplate(), c)
2 unmodified lines
242 }243 }244}245246// checkHelpFunc checks if there is helpFunc in ancestors of c.247func (c *Command) checkHelpFunc() func(*Command, []string) {248 if c == nil {249 return nil250 }251 if c.helpFunc != nil {252 return c.helpFunc253 }254 if c.HasParent() {255 return c.parent.checkHelpFunc()256 }257 return nil258}259260// Help puts out the help for the command.261// Used when a user calls help [command].262// Can be defined by user by overriding HelpFunc.263func (c *Command) Help() error {
1028 unmodified lines