forked from keybase/client
/
cmd_team_list_requests.go
72 lines (60 loc) · 1.58 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
package client
import (
"fmt"
"strings"
"text/tabwriter"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"golang.org/x/net/context"
)
type CmdTeamListRequests struct {
libkb.Contextified
}
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)
},
}
}
func NewCmdTeamListRequestsRunner(g *libkb.GlobalContext) *CmdTeamListRequests {
return &CmdTeamListRequests{Contextified: libkb.NewContextified(g)}
}
func (c *CmdTeamListRequests) ParseArgv(ctx *cli.Context) error {
return nil
}
func (c *CmdTeamListRequests) Run() error {
cli, err := GetTeamsClient(c.G())
if err != nil {
return err
}
reqs, err := cli.TeamListRequests(context.Background(), 0)
if err != nil {
return err
}
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()
dui.Printf("%s\n", strings.Repeat("-", 70))
dui.Printf("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,
}
}