forked from c-bata/go-prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (37 loc) · 796 Bytes
/
main.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
package main
import (
"fmt"
"os"
"strings"
"github.com/c-bata/go-prompt"
"github.com/c-bata/go-prompt/completer"
)
var filePathCompleter = completer.FilePathCompleter{
IgnoreCase: true,
Filter: func(fi os.FileInfo) bool {
return fi.IsDir() || strings.HasSuffix(fi.Name(), ".go")
},
}
func executor(in string) {
fmt.Println("Your input: " + in)
}
func completerFunc(d prompt.Document) []prompt.Suggest {
t := d.GetWordBeforeCursor()
if strings.HasPrefix(t, "--") {
return []prompt.Suggest{
{"--foo", ""},
{"--bar", ""},
{"--baz", ""},
}
}
return filePathCompleter.Complete(d)
}
func main() {
p := prompt.New(
executor,
completerFunc,
prompt.OptionPrefix(">>> "),
prompt.OptionCompletionWordSeparator(completer.FilePathCompletionSeparator),
)
p.Run()
}