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

Method Find

command.go:757–779  ·  view source on GitHub ↗

Find the target command given the args and command tree Meant to be run on the highest node. Only searches down.

(args []string)

Source from the content-addressed store, hash-verified

755// Find the target command given the args and command tree
756// Meant to be run on the highest node. Only searches down.
757func (c *Command) Find(args []string) (*Command, []string, error) {
758 var innerfind func(*Command, []string) (*Command, []string)
759
760 innerfind = func(c *Command, innerArgs []string) (*Command, []string) {
761 argsWOflags := stripFlags(innerArgs, c)
762 if len(argsWOflags) == 0 {
763 return c, innerArgs
764 }
765 nextSubCmd := argsWOflags[0]
766
767 cmd := c.findNext(nextSubCmd)
768 if cmd != nil {
769 return innerfind(cmd, c.argsMinusFirstX(innerArgs, nextSubCmd))
770 }
771 return c, innerArgs
772 }
773
774 commandFound, a := innerfind(c, args)
775 if commandFound.Args == nil {
776 return commandFound, a, legacyArgs(commandFound, stripFlags(a, commandFound))
777 }
778 return commandFound, a, nil
779}
780
781func (c *Command) findSuggestions(arg string) string {
782 if c.DisableSuggestions {

Callers 7

initCompleteCmdMethod · 0.95
TestDefaultCompletionCmdFunction · 0.95
TestFindFunction · 0.95
ExecuteCMethod · 0.95
getCompletionsMethod · 0.80
InitDefaultHelpCmdMethod · 0.80

Calls 4

findNextMethod · 0.95
argsMinusFirstXMethod · 0.95
stripFlagsFunction · 0.85
legacyArgsFunction · 0.85

Tested by 2

TestDefaultCompletionCmdFunction · 0.76
TestFindFunction · 0.76