2017-07-17 06:58:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-08-07 15:19:51 +00:00
|
|
|
"github.com/c-bata/go-prompt"
|
2017-07-17 06:58:28 +00:00
|
|
|
)
|
|
|
|
|
2017-08-07 15:19:51 +00:00
|
|
|
func executor(in string) {
|
|
|
|
fmt.Println("Your input: " + in)
|
2017-07-17 06:58:28 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 07:41:49 +00:00
|
|
|
func completer(in prompt.Document) []prompt.Suggest {
|
2017-08-07 15:19:51 +00:00
|
|
|
s := []prompt.Suggest{
|
2017-08-13 07:41:49 +00:00
|
|
|
{Text: "users", Description: "Store the username and age"},
|
|
|
|
{Text: "articles", Description: "Store the article text posted by user"},
|
|
|
|
{Text: "comments", Description: "Store the text commented to articles"},
|
|
|
|
{Text: "groups", Description: "Combine users with specific rules"},
|
2017-07-17 06:58:28 +00:00
|
|
|
}
|
2017-08-13 07:41:49 +00:00
|
|
|
return prompt.FilterHasPrefix(s, in.GetWordBeforeCursor(), true)
|
2017-07-17 06:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2017-08-07 15:19:51 +00:00
|
|
|
p := prompt.New(
|
2017-07-17 06:58:28 +00:00
|
|
|
executor,
|
|
|
|
completer,
|
|
|
|
prompt.OptionPrefix(">>> "),
|
2017-08-07 15:19:51 +00:00
|
|
|
prompt.OptionTitle("sql-prompt"),
|
2017-07-17 06:58:28 +00:00
|
|
|
)
|
2017-08-07 15:19:51 +00:00
|
|
|
p.Run()
|
2017-07-17 06:58:28 +00:00
|
|
|
}
|