github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/crypto/keys/client/root.go (about)

     1  // Dedicated to my love, Lexi.
     2  package client
     3  
     4  import (
     5  	"flag"
     6  
     7  	"github.com/gnolang/gno/tm2/pkg/commands"
     8  
     9  	"github.com/peterbourgon/ff/v3"
    10  	"github.com/peterbourgon/ff/v3/fftoml"
    11  )
    12  
    13  const (
    14  	mnemonicEntropySize = 256
    15  )
    16  
    17  type BaseCfg struct {
    18  	BaseOptions
    19  }
    20  
    21  func NewRootCmdWithBaseConfig(io commands.IO, base BaseOptions) *commands.Command {
    22  	cfg := &BaseCfg{
    23  		BaseOptions: base,
    24  	}
    25  
    26  	cmd := commands.NewCommand(
    27  		commands.Metadata{
    28  			ShortUsage: "<subcommand> [flags] [<arg>...]",
    29  			LongHelp:   "Manages private keys for the node",
    30  			Options: []ff.Option{
    31  				ff.WithConfigFileFlag("config"),
    32  				ff.WithConfigFileParser(fftoml.Parser),
    33  			},
    34  		},
    35  		cfg,
    36  		commands.HelpExec,
    37  	)
    38  
    39  	cmd.AddSubCommands(
    40  		NewAddCmd(cfg, io),
    41  		NewDeleteCmd(cfg, io),
    42  		NewGenerateCmd(cfg, io),
    43  		NewExportCmd(cfg, io),
    44  		NewImportCmd(cfg, io),
    45  		NewListCmd(cfg, io),
    46  		NewSignCmd(cfg, io),
    47  		NewVerifyCmd(cfg, io),
    48  		NewQueryCmd(cfg, io),
    49  		NewBroadcastCmd(cfg, io),
    50  		NewMakeTxCmd(cfg, io),
    51  	)
    52  
    53  	return cmd
    54  }
    55  
    56  func (c *BaseCfg) RegisterFlags(fs *flag.FlagSet) {
    57  	// Base options
    58  	fs.StringVar(
    59  		&c.Home,
    60  		"home",
    61  		c.Home,
    62  		"home directory",
    63  	)
    64  
    65  	fs.StringVar(
    66  		&c.Remote,
    67  		"remote",
    68  		c.Remote,
    69  		"remote node URL",
    70  	)
    71  
    72  	fs.BoolVar(
    73  		&c.Quiet,
    74  		"quiet",
    75  		c.Quiet,
    76  		"suppress output during execution",
    77  	)
    78  
    79  	fs.BoolVar(
    80  		&c.InsecurePasswordStdin,
    81  		"insecure-password-stdin",
    82  		c.Quiet,
    83  		"WARNING! take password from stdin",
    84  	)
    85  
    86  	fs.StringVar(
    87  		&c.Config,
    88  		"config",
    89  		c.Config,
    90  		"config file (optional)",
    91  	)
    92  }