-
Notifications
You must be signed in to change notification settings - Fork 0
/
completer.go
47 lines (37 loc) · 1.11 KB
/
completer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"strings"
"github.com/c-bata/go-prompt"
)
func completer(in prompt.Document) []prompt.Suggest {
if in.TextBeforeCursor() == "" {
return []prompt.Suggest{}
}
args := strings.Split(in.TextBeforeCursor(), " ")
return suggestWithArguments(args)
}
func suggestWithArguments(args []string) []prompt.Suggest {
if len(args) <= 1 {
return prompt.FilterHasPrefix(GetAllSuggestions(), args[0], true)
}
if len(args) >= 3 {
return []prompt.Suggest{}
}
cmd := args[0]
switch cmd {
case "COUNT":
suggestions := []prompt.Suggest{DatabasesCommand, RecordsCommand}
return prompt.FilterHasPrefix(suggestions, args[1], true)
case "DELETE":
suggestions := []prompt.Suggest{DatabaseCommand, RecordCommand}
return prompt.FilterHasPrefix(suggestions, args[1], true)
case "LIST":
suggestions := []prompt.Suggest{DatabasesCommand, RecordsCommand, TransactionsCommand}
return prompt.FilterHasPrefix(suggestions, args[1], true)
case "NEW":
suggestions := []prompt.Suggest{DatabaseCommand}
return prompt.FilterHasPrefix(suggestions, args[1], true)
default:
return []prompt.Suggest{}
}
}