-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_team_list_memberships.go
172 lines (151 loc) · 4.25 KB
/
cmd_team_list_memberships.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2017 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"context"
"errors"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
)
type CmdTeamListMemberships struct {
libkb.Contextified
team string
json bool
userAssertion string
includeImplicitTeams bool
showAll bool
verbose bool
showInviteID bool
verified bool
}
func (c *CmdTeamListMemberships) SetTeam(s string) {
c.team = s
}
func (c *CmdTeamListMemberships) SetJSON(b bool) {
c.json = b
}
func NewCmdTeamListMembershipsRunner(g *libkb.GlobalContext) *CmdTeamListMemberships {
return &CmdTeamListMemberships{Contextified: libkb.NewContextified(g)}
}
func newCmdTeamListMemberships(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
flags := []cli.Flag{
cli.BoolFlag{
Name: "j, json",
Usage: "Output memberships as JSON",
},
cli.StringFlag{
Name: "u, user",
Usage: "List memberships for a user assertion",
},
cli.BoolFlag{
Name: "all",
Usage: "Show all members of all teams you belong to",
},
cli.BoolFlag{
Name: "show-invite-id",
Usage: "Show invite IDs",
},
cli.BoolFlag{
Name: "v, verbose",
Usage: "Include more verbose output",
},
}
if develUsage {
flags = append(flags, cli.BoolFlag{
Name: "include-implicit-teams",
Usage: "[devel only] Include automatic teams that are not normally visible",
}, cli.BoolFlag{
Name: "verified",
Usage: "[devel only] Verify results by loading every team",
})
}
return cli.Command{
Name: "list-memberships",
ArgumentHelp: "[team name] [--user=username]",
Aliases: []string{"list-members"},
Usage: "List your teams, or people on a team.",
Action: func(c *cli.Context) {
cmd := NewCmdTeamListMembershipsRunner(g)
cl.ChooseCommand(cmd, "list-memberships", c)
},
Flags: flags,
}
}
func (c *CmdTeamListMemberships) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) > 1 {
return errors.New("at most one team name argument allowed, multiple found")
}
if len(ctx.Args()) > 0 {
c.team = ctx.Args()[0]
}
c.userAssertion = ctx.String("user")
c.includeImplicitTeams = ctx.Bool("include-implicit-teams")
c.verified = ctx.Bool("verified")
c.showAll = ctx.Bool("all")
c.showInviteID = ctx.Bool("show-invite-id")
if c.showAll {
if c.team != "" {
return errors.New("cannot specify a team and --all, please choose one")
}
if c.userAssertion != "" {
return errors.New("cannot specify a user and --all, please choose one")
}
}
c.json = ctx.Bool("json")
c.verbose = ctx.Bool("verbose")
return nil
}
func (c *CmdTeamListMemberships) Run() error {
cli, err := GetTeamsClient(c.G())
if err != nil {
return err
}
if c.team != "" {
return c.runGet(cli)
}
return c.runUser(cli)
}
func (c *CmdTeamListMemberships) runGet(cli keybase1.TeamsClient) error {
res, err := cli.GetAnnotatedTeamByName(context.Background(), c.team)
if err != nil {
return err
}
renderer := newTeamMembersRenderer(c.G(), c.json, c.showInviteID)
return renderer.output(res, c.team, c.verbose)
}
func (c *CmdTeamListMemberships) runUser(cli keybase1.TeamsClient) error {
var err error
var list keybase1.AnnotatedTeamList
if c.showAll {
arg := keybase1.TeamListTeammatesArg{
IncludeImplicitTeams: c.includeImplicitTeams,
}
list, err = cli.TeamListTeammates(context.Background(), arg)
} else if c.verified {
arg := keybase1.TeamListVerifiedArg{
UserAssertion: c.userAssertion,
IncludeImplicitTeams: c.includeImplicitTeams,
}
list, err = cli.TeamListVerified(context.Background(), arg)
} else {
arg := keybase1.TeamListUnverifiedArg{
UserAssertion: c.userAssertion,
IncludeImplicitTeams: c.includeImplicitTeams,
}
list, err = cli.TeamListUnverified(context.Background(), arg)
}
if err != nil {
return err
}
renderer := newTeamMembersRenderer(c.G(), c.json, c.showInviteID)
return renderer.outputTeams(list, c.showAll)
}
func (c *CmdTeamListMemberships) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}