/
home.go
50 lines (38 loc) · 874 Bytes
/
home.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
package main
import (
"fmt"
pb "github.com/clawio/clawio/proto/metadata"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"google.golang.org/grpc"
"os"
)
var homeCmd = &cobra.Command{
Use: "home",
Short: "Create user home directory",
Run: home,
}
func home(cmd *cobra.Command, args []string) {
token, err := getToken()
if err != nil {
fmt.Println("Authentication required")
os.Exit(1)
}
addr := os.Getenv("CLAWIO_CLI_META_ADDR")
con, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
fmt.Println("Cannot connect to server " + addr)
os.Exit(1)
}
defer con.Close()
c := pb.NewMetaClient(con)
in := &pb.HomeReq{}
in.AccessToken = token
ctx := context.Background()
_, err = c.Home(ctx, in)
if err != nil {
fmt.Println("Cannot create homedir: " + err.Error())
os.Exit(1)
}
fmt.Println("Home directory created")
}