ricochet-go/cli/cli.go

58 lines
915 B
Go
Raw Normal View History

2016-08-02 02:58:10 +00:00
package main
import (
2016-10-16 21:50:34 +00:00
"bytes"
"fmt"
rpc "github.com/special/notricochet/rpc"
2016-08-02 02:58:10 +00:00
"google.golang.org/grpc"
"gopkg.in/readline.v1"
2016-08-02 02:58:10 +00:00
"log"
"os"
2016-08-02 02:58:10 +00:00
)
const (
defaultAddress = "127.0.0.1:58281"
)
2016-10-16 21:50:34 +00:00
var LogBuffer bytes.Buffer
func main() {
2016-10-16 21:50:34 +00:00
input, err := readline.NewEx(&readline.Config{})
2016-08-02 23:28:26 +00:00
if err != nil {
2016-10-16 21:50:34 +00:00
fmt.Println(err)
os.Exit(1)
2016-08-02 23:28:26 +00:00
}
2016-10-16 21:50:34 +00:00
defer input.Close()
log.SetOutput(&LogBuffer)
2016-08-02 23:28:26 +00:00
2016-10-16 21:50:34 +00:00
conn, err := grpc.Dial(defaultAddress, grpc.WithInsecure())
if err != nil {
2016-10-16 21:50:34 +00:00
fmt.Printf("connection failed: %v\n", err)
os.Exit(1)
}
2016-10-16 21:50:34 +00:00
defer conn.Close()
client := &Client{
Backend: rpc.NewRicochetCoreClient(conn),
}
ui := &UI{
Input: input,
Client: client,
}
client.Ui = ui
2016-10-16 21:50:34 +00:00
fmt.Print("Connecting to backend...\n")
go func() {
if err := client.Initialize(); err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
client.Block()
ui.PrintStatus()
client.Unblock()
}()
ui.CommandLoop()
2016-08-02 02:58:10 +00:00
}