This Go package provides a dead simple 'terminal-prompt-like' for your application.
There is no extra dependencies, just a Go environment is needed. Then:
$ go get gopkg.in/prompt.v1
Here you can see an example about how to add a custom command.
package main
import (
"fmt"
"gopkg.in/prompt.v1"
)
func main() {
prompt.AddCommand(
"ping",
"my custom command",
func(args []string) {
fmt.Println("pong! Arguments:", args)
},
)
<-prompt.Start()
// if you don't need to lock, just remove the '<-' operator
fmt.Println("Bye from main!")
}
This example will show a terminal-prompt-shell-like, where you can try your custom command 'ping'. Or just type 'quit' to close it. For a list of commands type 'help'. You can see this in action here.
- a wrapper for exec.Command (from os standard library).