(commandText string, command *CommandDefinition, exclude []string)
| 135 | } |
| 136 | |
| 137 | func (a autoCompleteHandler) Find(commandText string, command *CommandDefinition, exclude []string) []string { |
| 138 | words := strings.Split(commandText, " ") |
| 139 | if len(words) < 2 { |
| 140 | return []string{} |
| 141 | } |
| 142 | |
| 143 | for _, word := range words[1 : len(words)-1] { |
| 144 | if strings.HasPrefix(word, "-") { |
| 145 | break |
| 146 | } |
| 147 | command = a.findCommand(word, command.Subcommands) |
| 148 | if command == nil { |
| 149 | return []string{} |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | lastWord := words[len(words)-1] |
| 154 | if strings.HasPrefix(lastWord, "-") { |
| 155 | return a.searchFlags(strings.TrimLeft(lastWord, "-"), command, append(exclude, words...)) |
| 156 | } |
| 157 | return a.searchCommands(lastWord, command.Subcommands, exclude) |
| 158 | } |
| 159 | |
| 160 | func (a autoCompleteHandler) findCommand(name string, commands []*CommandDefinition) *CommandDefinition { |
| 161 | for _, command := range commands { |
no test coverage detected