2017-07-23 15:35:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-08-07 09:48:33 +00:00
|
|
|
"context"
|
2017-08-14 16:48:07 +00:00
|
|
|
"fmt"
|
2017-08-07 09:48:33 +00:00
|
|
|
"os/exec"
|
2017-08-14 16:48:07 +00:00
|
|
|
"time"
|
2017-07-23 15:35:13 +00:00
|
|
|
|
2017-08-07 15:19:51 +00:00
|
|
|
"github.com/c-bata/go-prompt"
|
2017-07-23 15:35:13 +00:00
|
|
|
)
|
|
|
|
|
2017-08-07 09:48:33 +00:00
|
|
|
func executor(t string) {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
2017-07-23 15:35:13 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if t == "sleep 5s" {
|
|
|
|
cmd := exec.CommandContext(ctx, "sleep", "5")
|
|
|
|
cmd.Run()
|
|
|
|
} else if t == "sleep 20s" {
|
|
|
|
cmd := exec.CommandContext(ctx, "sleep", "20")
|
|
|
|
cmd.Run()
|
|
|
|
}
|
2017-08-06 06:31:44 +00:00
|
|
|
return
|
2017-07-23 15:35:13 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 07:41:49 +00:00
|
|
|
func completer(t prompt.Document) []prompt.Suggest {
|
2017-08-04 11:30:50 +00:00
|
|
|
return []prompt.Suggest{
|
2017-07-23 15:35:13 +00:00
|
|
|
{Text: "sleep 5s"},
|
|
|
|
{Text: "sleep 20s"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2017-08-07 15:19:51 +00:00
|
|
|
p := prompt.New(
|
2017-07-23 15:35:13 +00:00
|
|
|
executor,
|
|
|
|
completer,
|
|
|
|
)
|
2017-08-13 07:41:49 +00:00
|
|
|
defer fmt.Println("Goodbye!")
|
2017-08-07 15:19:51 +00:00
|
|
|
p.Run()
|
2017-07-23 15:35:13 +00:00
|
|
|
}
|