refactor reple into separete files
This commit is contained in:
31
pkg/cli/repl/completer.go
Normal file
31
pkg/cli/repl/completer.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package repl
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/c-bata/go-prompt"
|
||||
)
|
||||
|
||||
func completer(d prompt.Document) []prompt.Suggest {
|
||||
text := d.TextBeforeCursor()
|
||||
words := strings.Fields(text)
|
||||
|
||||
if len(words) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if words[0] != "pm" {
|
||||
return filterByPrefix(rootSuggestions, words[0])
|
||||
}
|
||||
|
||||
pmWords := words[1:]
|
||||
if len(words) == 1 || (len(pmWords) == 1 && !strings.HasSuffix(text, " ")) {
|
||||
return commandSuggestions(pmWords)
|
||||
}
|
||||
|
||||
if len(pmWords) >= 1 {
|
||||
return flagSuggestions(pmWords[0], pmWords, text)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user