Skip to content
Myr

Restore Help() and Usage() for backwards compatibility

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

authored by Fabiano Franz · committed by Fabiano Franz · parent 9d9ce12 · Browse files · 1 file+18 added−3 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+18 added−3 removed

  • other:+18 added−3 removed

1 file+18 added−3 removed

modified:command.go+18 added-3 removed
212 unmodified lines
213 return err214 }215}216217// Output the usage for the command218// Used when a user provides invalid input219// Can be defined by user by overriding UsageFunc220func (c *Command) Usage() error {221 return c.UsageFunc()(c)222}223224// HelpFunc returns either the function set by SetHelpFunc for this command225// or a parent, or it returns a function with default help behavior226func (c *Command) HelpFunc() func(*Command, []string) {227 cmd := c
11 unmodified lines
239 }240 }241}242243// Output the help for the command244// Used when a user calls help [command]245// Can be defined by user by overriding HelpFunc246func (c *Command) Help() error {247 c.HelpFunc()(c, []string{})248 return nil249}250251func (c *Command) UsageString() string {252 tmpOutput := c.output253 bb := new(bytes.Buffer)254 c.SetOutput(bb)240 c.UsageFunc()(c)255 c.Usage()256 c.output = tmpOutput257 return bb.String()258}259
474 unmodified lines
734 Run: func(c *Command, args []string) {735 cmd, _, e := c.Root().Find(args)736 if cmd == nil || e != nil {737 c.Printf("Unknown help topic %#q.", args)723 c.Root().UsageFunc()(cmd)738 c.Root().Usage()739 } else {725 cmd.HelpFunc()(cmd, args)740 cmd.Help()741 }742 },743 }744 }
512 unmodified lines