forked from keybase/client
/
cmd_list_followers.go
88 lines (77 loc) · 2.1 KB
/
cmd_list_followers.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
"golang.org/x/net/context"
)
// CmdListTrackers is the 'list-trackers' command. It displays
// all the trackers for a user.
type CmdListTrackers struct {
libkb.Contextified
assertion string
verbose bool
}
// NewCmdListTrackers creates a new cli.Command.
func NewCmdListTrackers(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "list-followers",
ArgumentHelp: "<username>",
Usage: "List those who follow you",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "v, verbose",
Usage: "A full dump, with more gory details.",
},
},
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdListTrackers{Contextified: libkb.NewContextified(g)}, "list-followers", c)
},
}
}
// RunClient runs the command in client/server mode.
func (c *CmdListTrackers) Run() error {
cli, err := GetUserClient(c.G())
if err != nil {
return err
}
if err := RegisterProtocolsWithContext(nil, c.G()); err != nil {
return err
}
arg := keybase1.ListTrackersUnverifiedArg{Assertion: c.assertion}
uss, err := cli.ListTrackersUnverified(context.TODO(), arg)
if err != nil {
return err
}
return c.output(uss)
}
func (c *CmdListTrackers) output(uss keybase1.UserSummarySet) (err error) {
dui := c.G().UI.GetDumbOutputUI()
if len(uss.Users) == 0 {
dui.Printf("no followers\n")
return nil
}
for _, user := range uss.Users {
dui.Printf("%s", user.Username)
dui.Printf("\n")
}
return nil
}
// ParseArgv parses the command args.
func (c *CmdListTrackers) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) == 1 {
c.assertion = ctx.Args()[0]
}
c.verbose = ctx.Bool("verbose")
return nil
}
// GetUsage says what this command needs to operate.
func (c *CmdListTrackers) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
}
}