-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmdInit.go
61 lines (53 loc) · 1.2 KB
/
cmdInit.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
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"time"
survey "github.com/AlecAivazis/survey/v2"
apic "github.com/protosio/protos/apic/proto"
"github.com/urfave/cli/v2"
)
var username string
var name string
var organization string
var cmdInit *cli.Command = &cli.Command{
Name: "init",
Usage: "Performs Protos user initialization",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Required: true,
Destination: &username,
},
&cli.StringFlag{
Name: "name",
Required: false,
Destination: &name,
DefaultText: username,
},
&cli.StringFlag{
Name: "organization",
Required: false,
Destination: &organization,
DefaultText: "home",
},
},
Action: func(c *cli.Context) error {
return protosUserinit()
},
}
func protosUserinit() error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := client.Init(ctx, &apic.InitRequest{Username: username, Name: name, Organization: organization})
if err != nil {
return err
}
log.Info("Initialization complete")
return nil
}
func surveySelect(options []string, message string) *survey.Select {
return &survey.Select{
Message: message,
Options: options,
}
}