/
cmd_team_accept_invite.go
75 lines (62 loc) · 1.66 KB
/
cmd_team_accept_invite.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package client
import (
"errors"
"golang.org/x/net/context"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
type CmdTeamAcceptInvite struct {
libkb.Contextified
Token string
}
func newCmdTeamAcceptInvite(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "accept-invite",
ArgumentHelp: "--token=<invite token>",
Usage: "Accept a team email invitation.",
Action: func(c *cli.Context) {
cmd := NewCmdTeamAcceptInviteRunner(g)
cl.ChooseCommand(cmd, "accept-invite", c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "token",
Usage: "token",
},
},
}
}
func NewCmdTeamAcceptInviteRunner(g *libkb.GlobalContext) *CmdTeamAcceptInvite {
return &CmdTeamAcceptInvite{Contextified: libkb.NewContextified(g)}
}
func (c *CmdTeamAcceptInvite) ParseArgv(ctx *cli.Context) error {
c.Token = ctx.String("token")
if len(c.Token) == 0 {
return errors.New("please specify an invite token with the --token flag")
}
return nil
}
func (c *CmdTeamAcceptInvite) Run() error {
cli, err := GetTeamsClient(c.G())
if err != nil {
return err
}
arg := keybase1.TeamAcceptInviteArg{
Token: c.Token,
}
if err := cli.TeamAcceptInvite(context.Background(), arg); err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
dui.Printf("Invitation accepted! You will receive a notification soon when your invitation has been processed.\n")
return nil
}
func (c *CmdTeamAcceptInvite) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}