ricochet-go/cli/cli.go

49 lines
766 B
Go
Raw Normal View History

2016-08-02 04:58:10 +02:00
package main
import (
"fmt"
rpc "github.com/special/notricochet/rpc"
2016-08-02 04:58:10 +02:00
"google.golang.org/grpc"
"gopkg.in/readline.v1"
2016-08-02 04:58:10 +02:00
"log"
"os"
2016-08-02 04:58:10 +02:00
)
const (
defaultAddress = "127.0.0.1:58281"
)
func main() {
conn, err := grpc.Dial(defaultAddress, grpc.WithInsecure())
2016-08-03 01:28:26 +02:00
if err != nil {
fmt.Printf("connection failed: %v\n", err)
os.Exit(1)
2016-08-03 01:28:26 +02:00
}
defer conn.Close()
2016-08-03 01:28:26 +02:00
input, err := readline.NewEx(&readline.Config{})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer input.Close()
log.SetOutput(input.Stdout())
client := &Client{
Backend: rpc.NewRicochetCoreClient(conn),
}
ui := &UI{
Input: input,
Client: client,
}
client.Ui = ui
if err := client.Initialize(); err != nil {
fmt.Println(err)
os.Exit(1)
}
go client.Run()
ui.CommandLoop()
2016-08-02 04:58:10 +02:00
}