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

     1  package client
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/keybase/cli"
     7  	"github.com/keybase/client/go/libcmdline"
     8  	"github.com/keybase/client/go/libkb"
     9  	"golang.org/x/net/context"
    10  )
    11  
    12  func (c *cmdWalletPopularAssets) GetUsage() libkb.Usage {
    13  	return libkb.Usage{
    14  		API:       true,
    15  		KbKeyring: true,
    16  		Config:    true,
    17  	}
    18  }
    19  
    20  type cmdWalletPopularAssets struct {
    21  	libkb.Contextified
    22  }
    23  
    24  func newCmdWalletPopularAssets(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    25  	cmd := &cmdWalletPopularAssets{
    26  		Contextified: libkb.NewContextified(g),
    27  	}
    28  	return cli.Command{
    29  		Name:  "popular-assets",
    30  		Usage: "List popular assets",
    31  		Action: func(c *cli.Context) {
    32  			cl.ChooseCommand(cmd, "popular-assets", c)
    33  		},
    34  	}
    35  }
    36  
    37  func (c *cmdWalletPopularAssets) ParseArgv(ctx *cli.Context) error {
    38  	if len(ctx.Args()) != 0 {
    39  		return errors.New("listing popular assets expects no args")
    40  	}
    41  	return nil
    42  }
    43  
    44  func (c *cmdWalletPopularAssets) Run() (err error) {
    45  	defer transformStellarCLIError(&err)
    46  
    47  	cli, err := GetWalletClient(c.G())
    48  	if err != nil {
    49  		return err
    50  	}
    51  
    52  	assetRes, err := cli.ListPopularAssetsLocal(context.Background(), 0)
    53  	if err != nil {
    54  		return err
    55  	}
    56  	dui := c.G().UI.GetDumbOutputUI()
    57  	dui.Printf("popular assets from a total of %d:\n", assetRes.TotalCount)
    58  	for _, asset := range assetRes.Assets {
    59  		dui.Printf(buildOutputStringForAsset(asset) + "\n")
    60  	}
    61  	return nil
    62  }