/
update.go
52 lines (40 loc) · 1008 Bytes
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"context"
pb "github.com/arr-ai/proto"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"github.com/arr-ai/arrai/pkg/arraictx"
)
var updateCommand = &cli.Command{
Name: "update",
Aliases: []string{"u"},
Usage: "update a server with an expression",
Action: update,
}
func update(c *cli.Context) error {
server := arraiAddress(c.Args().Get(0))
source := c.Args().Get(1)
logrus.Infof("Server: %s", server)
logrus.Infof("Source: %s", source)
conn, err := grpc.Dial(server, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}
defer conn.Close()
client := pb.NewArraiClient(conn)
update, err := client.Update(arraictx.InitRunCtx(context.Background()))
if err != nil {
return err
}
if err := update.Send(&pb.UpdateReq{Expr: source}); err != nil {
return err
}
_, err = update.Recv()
if err != nil {
return err
}
return nil
}