UsageFunc returns either the function set by SetUsageFunc for this command or a parent, or it returns a default usage function.
()
| 442 | // UsageFunc returns either the function set by SetUsageFunc for this command |
| 443 | // or a parent, or it returns a default usage function. |
| 444 | func (c *Command) UsageFunc() (f func(*Command) error) { |
| 445 | if c.usageFunc != nil { |
| 446 | return c.usageFunc |
| 447 | } |
| 448 | if c.HasParent() { |
| 449 | return c.Parent().UsageFunc() |
| 450 | } |
| 451 | return func(c *Command) error { |
| 452 | c.mergePersistentFlags() |
| 453 | fn := c.getUsageTemplateFunc() |
| 454 | err := fn(c.OutOrStderr(), c) |
| 455 | if err != nil { |
| 456 | c.PrintErrln(err) |
| 457 | } |
| 458 | return err |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | // getUsageTemplateFunc returns the usage template function for the command |
| 463 | // going up the command tree if necessary. |
no test coverage detected