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

Method SuggestionsFor

command.go:863–881  ·  view source on GitHub ↗

SuggestionsFor provides suggestions for the typedName.

(typedName string)

Source from the content-addressed store, hash-verified

861
862// SuggestionsFor provides suggestions for the typedName.
863func (c *Command) SuggestionsFor(typedName string) []string {
864 suggestions := []string{}
865 for _, cmd := range c.commands {
866 if cmd.IsAvailableCommand() {
867 levenshteinDistance := ld(typedName, cmd.Name(), true)
868 suggestByLevenshtein := levenshteinDistance <= c.SuggestionsMinimumDistance
869 suggestByPrefix := strings.HasPrefix(strings.ToLower(cmd.Name()), strings.ToLower(typedName))
870 if suggestByLevenshtein || suggestByPrefix {
871 suggestions = append(suggestions, cmd.Name())
872 }
873 for _, explicitSuggestion := range cmd.SuggestFor {
874 if strings.EqualFold(typedName, explicitSuggestion) {
875 suggestions = append(suggestions, cmd.Name())
876 }
877 }
878 }
879 }
880 return suggestions
881}
882
883// VisitParents visits all parents of the command and invokes fn on each parent.
884func (c *Command) VisitParents(fn func(*Command)) {

Callers 1

findSuggestionsMethod · 0.95

Calls 3

ldFunction · 0.85
IsAvailableCommandMethod · 0.80
NameMethod · 0.80

Tested by

no test coverage detected