ricochet-go/cli/cli.go

58 lines
933 B
Go
Raw Normal View History

2016-08-02 04:58:10 +02:00
package main
import (
2016-10-16 23:50:34 +02:00
"bytes"
"fmt"
2016-10-23 20:37:57 +02:00
"github.com/chzyer/readline"
2016-10-17 06:26:35 +02:00
rpc "github.com/ricochet-im/ricochet-go/rpc"
2016-08-02 04:58:10 +02:00
"google.golang.org/grpc"
"log"
"os"
2016-08-02 04:58:10 +02:00
)
const (
defaultAddress = "127.0.0.1:58281"
)
2016-10-16 23:50:34 +02:00
var LogBuffer bytes.Buffer
func main() {
2016-10-16 23:50:34 +02:00
input, err := readline.NewEx(&readline.Config{})
2016-08-03 01:28:26 +02:00
if err != nil {
2016-10-16 23:50:34 +02:00
fmt.Println(err)
os.Exit(1)
2016-08-03 01:28:26 +02:00
}
2016-10-16 23:50:34 +02:00
defer input.Close()
log.SetOutput(&LogBuffer)
2016-08-03 01:28:26 +02:00
2016-10-16 23:50:34 +02:00
conn, err := grpc.Dial(defaultAddress, grpc.WithInsecure())
if err != nil {
2016-10-16 23:50:34 +02:00
fmt.Printf("connection failed: %v\n", err)
os.Exit(1)
}
2016-10-16 23:50:34 +02:00
defer conn.Close()
client := &Client{
Backend: rpc.NewRicochetCoreClient(conn),
}
2016-10-23 02:50:21 +02:00
Ui = UI{
Input: input,
Stdout: input.Stdout(),
Client: client,
}
2016-10-16 23:50:34 +02: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()
2016-10-23 02:50:21 +02:00
Ui.PrintStatus()
2016-10-16 23:50:34 +02:00
client.Unblock()
}()
2016-10-23 02:50:21 +02:00
Ui.CommandLoop()
2016-08-02 04:58:10 +02:00
}