2018-06-23 19:30:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2018-12-09 11:42:33 +00:00
|
|
|
prompt "github.com/c-bata/go-prompt"
|
2018-06-23 19:30:37 +00:00
|
|
|
"github.com/c-bata/go-prompt/completer"
|
|
|
|
)
|
|
|
|
|
2018-10-20 04:06:36 +00:00
|
|
|
var filePathCompleter = completer.FilePathCompleter{
|
|
|
|
IgnoreCase: true,
|
|
|
|
Filter: func(fi os.FileInfo) bool {
|
|
|
|
return fi.IsDir() || strings.HasSuffix(fi.Name(), ".go")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-06-23 19:30:37 +00:00
|
|
|
func executor(in string) {
|
|
|
|
fmt.Println("Your input: " + in)
|
|
|
|
}
|
|
|
|
|
2018-10-20 04:06:36 +00:00
|
|
|
func completerFunc(d prompt.Document) []prompt.Suggest {
|
|
|
|
t := d.GetWordBeforeCursor()
|
|
|
|
if strings.HasPrefix(t, "--") {
|
|
|
|
return []prompt.Suggest{
|
|
|
|
{"--foo", ""},
|
|
|
|
{"--bar", ""},
|
|
|
|
{"--baz", ""},
|
|
|
|
}
|
2018-06-23 19:30:37 +00:00
|
|
|
}
|
2018-10-20 04:06:36 +00:00
|
|
|
return filePathCompleter.Complete(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2018-06-23 19:30:37 +00:00
|
|
|
p := prompt.New(
|
|
|
|
executor,
|
2018-10-20 04:06:36 +00:00
|
|
|
completerFunc,
|
2018-06-23 19:30:37 +00:00
|
|
|
prompt.OptionPrefix(">>> "),
|
|
|
|
prompt.OptionCompletionWordSeparator(completer.FilePathCompletionSeparator),
|
|
|
|
)
|
|
|
|
p.Run()
|
|
|
|
}
|