-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_team_list_requests.go
112 lines (96 loc) · 2.46 KB
/
cmd_team_list_requests.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package client
import (
"encoding/json"
"fmt"
"strings"
"text/tabwriter"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
)
type CmdTeamListRequests struct {
libkb.Contextified
json bool
team string
}
func newCmdTeamListRequests(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "list-requests",
Usage: "List requests to join teams.",
Action: func(c *cli.Context) {
cmd := NewCmdTeamListRequestsRunner(g)
cl.ChooseCommand(cmd, "list-requests", c)
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "j, json",
Usage: "Output requests as JSON",
},
cli.StringFlag{
Name: "t, team",
Usage: "List request for specific team",
},
},
}
}
func NewCmdTeamListRequestsRunner(g *libkb.GlobalContext) *CmdTeamListRequests {
return &CmdTeamListRequests{Contextified: libkb.NewContextified(g)}
}
func (c *CmdTeamListRequests) ParseArgv(ctx *cli.Context) error {
c.json = ctx.Bool("json")
c.team = ctx.String("team")
return nil
}
func (c *CmdTeamListRequests) Run() error {
cli, err := GetTeamsClient(c.G())
if err != nil {
return err
}
arg := keybase1.TeamListRequestsArg{}
if c.team != "" {
arg.TeamName = &c.team
}
reqs, err := cli.TeamListRequests(context.Background(), arg)
if err != nil {
return err
}
if c.json {
return c.outputJSON(reqs)
}
return c.outputTerminal(reqs)
}
func (c *CmdTeamListRequests) outputJSON(reqs []keybase1.TeamJoinRequest) error {
b, err := json.MarshalIndent(reqs, "", " ")
if err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
_, err = dui.Printf(string(b) + "\n")
return err
}
func (c *CmdTeamListRequests) outputTerminal(reqs []keybase1.TeamJoinRequest) error {
dui := c.G().UI.GetTerminalUI()
if len(reqs) == 0 {
dui.Printf("No requests at this time.\n")
return nil
}
tabw := new(tabwriter.Writer)
tabw.Init(dui.OutputWriter(), 0, 8, 2, ' ', 0)
for _, req := range reqs {
fmt.Fprintf(tabw, "%s\t%s wants to join\n", req.Name, req.Username)
}
tabw.Flush()
werr := dui.ErrorWriter()
fmt.Fprintf(werr, "%s\n", strings.Repeat("-", 70))
fmt.Fprintf(werr, "To handle requests, use `keybase team add-member` or `keybase team ignore-request`.\n")
return nil
}
func (c *CmdTeamListRequests) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}