github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/client/cmd_list_followers.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package client
     5  
     6  import (
     7  	"github.com/keybase/cli"
     8  	"github.com/keybase/client/go/libcmdline"
     9  	"github.com/keybase/client/go/libkb"
    10  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    11  	"golang.org/x/net/context"
    12  )
    13  
    14  // CmdListTrackers is the 'list-trackers' command.  It displays
    15  // all the trackers for a user.
    16  type CmdListTrackers struct {
    17  	libkb.Contextified
    18  	assertion string
    19  	verbose   bool
    20  }
    21  
    22  // NewCmdListTrackers creates a new cli.Command.
    23  func NewCmdListTrackers(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    24  	return cli.Command{
    25  		Name:         "list-followers",
    26  		ArgumentHelp: "<username>",
    27  		Usage:        "List those who follow you",
    28  		Flags: []cli.Flag{
    29  			cli.BoolFlag{
    30  				Name:  "v, verbose",
    31  				Usage: "A full dump, with more gory details.",
    32  			},
    33  		},
    34  		Action: func(c *cli.Context) {
    35  			cl.ChooseCommand(&CmdListTrackers{Contextified: libkb.NewContextified(g)}, "list-followers", c)
    36  		},
    37  	}
    38  }
    39  
    40  // RunClient runs the command in client/server mode.
    41  func (c *CmdListTrackers) Run() error {
    42  	cli, err := GetUserClient(c.G())
    43  	if err != nil {
    44  		return err
    45  	}
    46  	if err := RegisterProtocolsWithContext(nil, c.G()); err != nil {
    47  		return err
    48  	}
    49  
    50  	arg := keybase1.ListTrackersUnverifiedArg{Assertion: c.assertion}
    51  	uss, err := cli.ListTrackersUnverified(context.TODO(), arg)
    52  	if err != nil {
    53  		return err
    54  	}
    55  	return c.output(uss)
    56  }
    57  
    58  func (c *CmdListTrackers) output(uss keybase1.UserSummarySet) (err error) {
    59  	dui := c.G().UI.GetDumbOutputUI()
    60  	if len(uss.Users) == 0 {
    61  		dui.Printf("no followers\n")
    62  		return nil
    63  	}
    64  
    65  	for _, user := range uss.Users {
    66  		dui.Printf("%s", user.Username)
    67  		dui.Printf("\n")
    68  	}
    69  	return nil
    70  }
    71  
    72  // ParseArgv parses the command args.
    73  func (c *CmdListTrackers) ParseArgv(ctx *cli.Context) error {
    74  	if len(ctx.Args()) == 1 {
    75  		c.assertion = ctx.Args()[0]
    76  	}
    77  
    78  	c.verbose = ctx.Bool("verbose")
    79  	return nil
    80  }
    81  
    82  // GetUsage says what this command needs to operate.
    83  func (c *CmdListTrackers) GetUsage() libkb.Usage {
    84  	return libkb.Usage{
    85  		Config: true,
    86  		API:    true,
    87  	}
    88  }