go-prompt/_tools/complete_file/main.go
2018-06-24 18:08:06 +09:00

31 lines
530 B
Go

package main
import (
"fmt"
"os"
"strings"
"github.com/c-bata/go-prompt"
"github.com/c-bata/go-prompt/completer"
)
func executor(in string) {
fmt.Println("Your input: " + in)
}
func main() {
c := completer.FilePathCompleter{
IgnoreCase: true,
Filter: func(fi os.FileInfo) bool {
return fi.IsDir() || strings.HasSuffix(fi.Name(), ".go")
},
}
p := prompt.New(
executor,
c.Complete,
prompt.OptionPrefix(">>> "),
prompt.OptionCompletionWordSeparator(completer.FilePathCompletionSeparator),
)
p.Run()
}