SuggestionsFor provides suggestions for the typedName.
(typedName string)
| 861 | |
| 862 | // SuggestionsFor provides suggestions for the typedName. |
| 863 | func (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. |
| 884 | func (c *Command) VisitParents(fn func(*Command)) { |
no test coverage detected