ricochet-go/cli/cli.go

61 lines
987 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"
2016-10-23 18:37:57 +00:00
"github.com/chzyer/readline"
2016-10-17 04:26:35 +00:00
rpc "github.com/ricochet-im/ricochet-go/rpc"
2016-08-02 02:58:10 +00:00
"google.golang.org/grpc"
"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-26 21:26:21 +00:00
input, err := readline.NewEx(&readline.Config{
InterruptPrompt: "^C",
EOFPrompt: "exit",
})
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),
}
2016-10-23 00:50:21 +00:00
Ui = UI{
Input: input,
Stdout: input.Stdout(),
Client: client,
}
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()
2016-10-23 00:50:21 +00:00
Ui.PrintStatus()
2016-10-16 21:50:34 +00:00
client.Unblock()
}()
2016-10-23 00:50:21 +00:00
Ui.CommandLoop()
2016-08-02 02:58:10 +00:00
}