refactor reple into separete files

This commit is contained in:
Robin Olsen
2026-02-07 13:40:59 +01:00
parent 317feadde2
commit 419fcfaaa3
6 changed files with 265 additions and 235 deletions

31
pkg/cli/repl/completer.go Normal file
View 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
}