MCPcopy
hub / github.com/spf13/cobra / UsageFunc

Method UsageFunc

command.go:444–460  ·  view source on GitHub ↗

UsageFunc returns either the function set by SetUsageFunc for this command or a parent, or it returns a default usage function.

()

Source from the content-addressed store, hash-verified

442// UsageFunc returns either the function set by SetUsageFunc for this command
443// or a parent, or it returns a default usage function.
444func (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.

Callers 1

UsageMethod · 0.95

Calls 6

HasParentMethod · 0.95
ParentMethod · 0.95
mergePersistentFlagsMethod · 0.95
getUsageTemplateFuncMethod · 0.95
OutOrStderrMethod · 0.95
PrintErrlnMethod · 0.95

Tested by

no test coverage detected