Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateSeed(length uint8) ([]byte, error)
- func GetConfigBase(in config.Opts, appName string, abs bool)
- func HelpEntrypoint(c *Command, args []string) (err error)
- func IndentTextBlock(s string, tabs int) (o string)
- type Command
- func (c *Command) AddCommand(cm *Command)
- func (c *Command) ForEach(cl func(*Command, int) bool, hereDepth, hereDist int, cmd *Command) (ocl func(*Command, int) bool, depth, dist int, cm *Command)
- func (c *Command) GetCommand(p string) (o *Command)
- func (c *Command) GetEnvs(path ...string) (envs Envs)
- func (c *Command) GetOpt(path path.Path) (o config.Option)
- func (c *Command) LoadConfig() (err error)
- func (c *Command) MarshalText() (text []byte, err error)
- func (c *Command) ParseCLIArgs(a []string) (run *Command, runArgs []string, err error)
- func (c *Command) SaveConfig() (err error)
- func (c *Command) UnmarshalText(t []byte) (err error)
- type CommandInfo
- type CommandInfos
- type Commands
- type Entries
- type Entry
- type Env
- type Envs
- type Op
Constants ¶
const ( // RecommendedSeedLen is the recommended length in bytes for a seed to a master node. RecommendedSeedLen = 32 // 256 bits // HardenedKeyStart is the index at which a hardened key starts. Each extended key has 2^31 normal child keys and // 2^31 hardned child keys. Thus the range for normal child keys is [0, 2^31 - 1] and the range for hardened child // keys is [2^31, 2^32 - 1]. HardenedKeyStart = 0x80000000 // 2^31 // MinSeedBytes is the minimum number of bytes allowed for a seed to a master node. MinSeedBytes = 16 // 128 bits // MaxSeedBytes is the maximum number of bytes allowed for a seed to a master node. MaxSeedBytes = 64 // 512 bits )
Variables ¶
var ( ErrInvalidSeedLen = fmt.Errorf( "seed length must be between %d and %d "+ "bits", MinSeedBytes*8, MaxSeedBytes*8, ) )
var NoOp = func(c *Command, args []string) error { return nil }
var Tags = func(s ...string) []string {
return s
}
Functions ¶
func GenerateSeed ¶
GenerateSeed returns a cryptographically secure random seed that can be used as the input for the NewMaster function to generate a new master node. The length is in bytes and it must be between 16 and 64 (128 to 512 bits). The recommended length is 32 (256 bits) as defined by the RecommendedSeedLen constant.
func GetConfigBase ¶
GetConfigBase creates an option set that should go in the root of a Command specification for an application, providing a data directory path and config file path.
This exists in order to simplify setup for application configuration persistence.
func HelpEntrypoint ¶
func IndentTextBlock ¶
IndentTextBlock adds an arbitrary number of tabs to the front of a text block that is presumed to already be flowed to ~80 columns.
Types ¶
type Command ¶
type Command struct { path.Path Name string Description string Documentation string Entrypoint Op Parent *Command Commands Commands Configs config.Opts Default []string // specifies default subcommand to execute sync.Mutex }
Command is a specification for a command and can include any number of subcommands, and for each Command a list of options
func GetExampleCommands ¶
func GetExampleCommands() (c *Command)
GetExampleCommands returns available subcommands in hypothetical Parallelcoin Pod example for testing (derived from btcd and btcwallet plus parallelcoin kopach miner)
func Init ¶
Init sets up a Command to be ready to use. Puts the reverse paths into the tree structure, puts sane defaults into command launchers, runs the hooks on all the defined configuration values, and sets the paths on each Command and Option so that they can be directly interrogated for their location.
func (*Command) AddCommand ¶
func (*Command) ForEach ¶
func (c *Command) ForEach(cl func(*Command, int) bool, hereDepth, hereDist int, cmd *Command) (ocl func(*Command, int) bool, depth, dist int, cm *Command)
ForEach runs a closure on every node in the Commands tree, stopping if the closure returns false
func (*Command) GetCommand ¶
func (*Command) GetEnvs ¶
GetEnvs walks a Command tree and returns a slice containing all environment variable names and the related config.Option.
func (*Command) LoadConfig ¶
func (*Command) MarshalText ¶
func (*Command) ParseCLIArgs ¶
ParseCLIArgs reads a command line argument slice (presumably from os.Args), identifies the command to run and
Rules for constructing CLI args:
Commands are identified by name, and must appear in their hierarchic order to invoke subcommands. They are matched as normalised to lower case.
Options can be preceded by "--" or "-", and the full name, or the alias, normalised to lower case for matching, and if there is an "=" after it, the value is after this, otherwise, the next element in the args is the value, except booleans, which default to true unless set to false. For these, the prefix "no" or similar indicates the semantics of the true value.
Options only match when preceded by their relevant Command, except for the root Command, and these options must precede any other command options.
If no command is selected, the root Command.Default is selected. This can optionally be used for subcommands as well, though it is unlikely needed, if found, the Default of the tip of the Command branch selected by the CLI if there is one, otherwise the Command itself.
func (*Command) SaveConfig ¶
func (*Command) UnmarshalText ¶
type CommandInfo ¶
type CommandInfo struct {
// contains filtered or unexported fields
}
type CommandInfos ¶
type CommandInfos []*CommandInfo
func (CommandInfos) Len ¶
func (c CommandInfos) Len() int
func (CommandInfos) Less ¶
func (c CommandInfos) Less(i, j int) bool
func (CommandInfos) Swap ¶
func (c CommandInfos) Swap(i, j int)