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

Method findNext

command.go:798–817  ·  view source on GitHub ↗
(next string)

Source from the content-addressed store, hash-verified

796}
797
798func (c *Command) findNext(next string) *Command {
799 matches := make([]*Command, 0)
800 for _, cmd := range c.commands {
801 if commandNameMatches(cmd.Name(), next) || cmd.HasAlias(next) {
802 cmd.commandCalledAs.name = next
803 return cmd
804 }
805 if EnablePrefixMatching && cmd.hasNameOrAliasPrefix(next) {
806 matches = append(matches, cmd)
807 }
808 }
809
810 if len(matches) == 1 {
811 // Temporarily disable gosec G602, which produces a false positive.
812 // See https://github.com/securego/gosec/issues/1005.
813 return matches[0] // #nosec G602
814 }
815
816 return nil
817}
818
819// Traverse the command tree to find the command, and parse args for
820// each parent.

Callers 2

FindMethod · 0.95
TraverseMethod · 0.95

Calls 4

commandNameMatchesFunction · 0.85
NameMethod · 0.80
HasAliasMethod · 0.80
hasNameOrAliasPrefixMethod · 0.80

Tested by

no test coverage detected