-
Notifications
You must be signed in to change notification settings - Fork 28
/
add.go
60 lines (54 loc) · 1.58 KB
/
add.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
package member
import (
"fmt"
"github.com/appcelerator/amp/api/rpc/account"
"github.com/appcelerator/amp/cli"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
type addTeamMemOptions struct {
org string
team string
member string
}
// NewAddTeamMemCommand returns a new instance of the add team member command.
func NewAddTeamMemCommand(c cli.Interface) *cobra.Command {
opts := addTeamMemOptions{}
cmd := &cobra.Command{
Use: "add [OPTIONS]",
Short: "Add member to team",
PreRunE: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return addTeamMem(c, cmd, opts)
},
}
flags := cmd.Flags()
flags.StringVar(&opts.org, "org", "", "Organization name")
flags.StringVar(&opts.team, "team", "", "Team name")
flags.StringVar(&opts.member, "member", "", "Member name")
return cmd
}
func addTeamMem(c cli.Interface, cmd *cobra.Command, opts addTeamMemOptions) error {
if !cmd.Flag("org").Changed {
opts.org = c.Console().GetInput("organization name")
}
if !cmd.Flag("team").Changed {
opts.team = c.Console().GetInput("team name")
}
if !cmd.Flag("member").Changed {
opts.member = c.Console().GetInput("member name")
}
conn := c.ClientConn()
client := account.NewAccountClient(conn)
request := &account.AddUserToTeamRequest{
OrganizationName: opts.org,
TeamName: opts.team,
UserName: opts.member,
}
if _, err := client.AddUserToTeam(context.Background(), request); err != nil {
return fmt.Errorf("%s", grpc.ErrorDesc(err))
}
c.Console().Println("Member has been added to team.")
return nil
}