2016-08-02 02:58:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-10-16 21:50:34 +00:00
|
|
|
"bytes"
|
2016-08-17 00:58:39 +00:00
|
|
|
"fmt"
|
2016-08-02 23:33:05 +00:00
|
|
|
rpc "github.com/special/notricochet/rpc"
|
2016-08-02 02:58:10 +00:00
|
|
|
"google.golang.org/grpc"
|
2016-08-17 00:58:39 +00:00
|
|
|
"gopkg.in/readline.v1"
|
2016-08-02 02:58:10 +00:00
|
|
|
"log"
|
2016-09-30 05:17:03 +00:00
|
|
|
"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
|
|
|
|
|
2016-08-17 00:58:39 +00:00
|
|
|
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)
|
2016-09-30 05:17:03 +00:00
|
|
|
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())
|
2016-08-17 00:58:39 +00:00
|
|
|
if err != nil {
|
2016-10-16 21:50:34 +00:00
|
|
|
fmt.Printf("connection failed: %v\n", err)
|
2016-09-30 05:17:03 +00:00
|
|
|
os.Exit(1)
|
2016-08-17 00:58:39 +00:00
|
|
|
}
|
2016-10-16 21:50:34 +00:00
|
|
|
defer conn.Close()
|
2016-08-17 00:58:39 +00:00
|
|
|
|
2016-10-16 04:57:16 +00:00
|
|
|
client := &Client{
|
2016-08-17 00:58:39 +00:00
|
|
|
Backend: rpc.NewRicochetCoreClient(conn),
|
|
|
|
}
|
2016-10-16 04:57:16 +00:00
|
|
|
ui := &UI{
|
|
|
|
Input: input,
|
|
|
|
Client: client,
|
|
|
|
}
|
|
|
|
client.Ui = ui
|
2016-08-17 00:58:39 +00:00
|
|
|
|
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()
|
|
|
|
}()
|
2016-08-17 00:58:39 +00:00
|
|
|
|
2016-10-16 04:57:16 +00:00
|
|
|
ui.CommandLoop()
|
2016-08-02 02:58:10 +00:00
|
|
|
}
|