Find the target command given the args and command tree Meant to be run on the highest node. Only searches down.
(args []string)
| 755 | // Find the target command given the args and command tree |
| 756 | // Meant to be run on the highest node. Only searches down. |
| 757 | func (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 | |
| 781 | func (c *Command) findSuggestions(arg string) string { |
| 782 | if c.DisableSuggestions { |