Documentation ¶
Index ¶
- type Cli
- type SubcommandHandler
- func (h *SubcommandHandler) AddBoolArg(aliases []string, doc string) error
- func (h *SubcommandHandler) AddBoolParamWithDefault(aliases []string, doc string, deflt bool) error
- func (h *SubcommandHandler) AddFloatArg(aliases []string, doc string) error
- func (h *SubcommandHandler) AddFloatParamWithDefault(aliases []string, doc string, deflt float64) error
- func (h *SubcommandHandler) AddIntArg(aliases []string, doc string) error
- func (h *SubcommandHandler) AddIntParamWithDefault(aliases []string, doc string, deflt int) error
- func (h *SubcommandHandler) AddStrArg(aliases []string, doc string) error
- func (h *SubcommandHandler) AddStrParamWithDefault(aliases []string, doc string, deflt string) error
- func (h *SubcommandHandler) Example(doc string, cmd string, out string)
- func (h *SubcommandHandler) GetBool(key string) (val bool, err error)
- func (h *SubcommandHandler) GetFloat(key string) (float64, error)
- func (h *SubcommandHandler) GetInt(key string) (int, error)
- func (h *SubcommandHandler) GetStr(key string) (string, error)
- func (h *SubcommandHandler) Handle(f func(insub *SubcommandHandler))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cli ¶
type Cli struct {
// contains filtered or unexported fields
}
The CLI "server" object
func NewCli ¶
Create a new Cli instance.
This Cli will do nothing when run is called unless it is mutated. The argument `version` should be a string describing the version of the CLI e.g. "2.1.3", "beta", "latest", &c The argument `doc` should contain brief documentation of the command.
func (*Cli) HandleSubcommand ¶
func (cli *Cli) HandleSubcommand(subcmd *SubcommandHandler)
Add a subcommand to the CLI instance.
type SubcommandHandler ¶
type SubcommandHandler struct {
// contains filtered or unexported fields
}
Handle a CLI subcommand.
For each row in ints, each element in the row can be used internally to refer to the value given at the command line. For example, if ints is [["a", "apple"]], then GetInt("a") should equal GetInt("apple") no matter what the user wrote at the command line.
func NewSubcommandHandler ¶
func NewSubcommandHandler(name string, doc string) (*SubcommandHandler, error)
Create a new SubcommandHandler instance. An error may occur if the subcommand labels are not valid e.g. if the one of the labels had a leading '-'.
func (*SubcommandHandler) AddBoolArg ¶
func (h *SubcommandHandler) AddBoolArg(aliases []string, doc string) error
Add a boolean argument to the subcommand. Warning, the subcommand will always fail if the argument is not set. If one of the aliases is used by another argument or parameter, the function will return an error and handler will not be mutated.
func (*SubcommandHandler) AddBoolParamWithDefault ¶
func (h *SubcommandHandler) AddBoolParamWithDefault(aliases []string, doc string, deflt bool) error
Add a boolean parameter to the subcommand with a default value.
func (*SubcommandHandler) AddFloatArg ¶
func (h *SubcommandHandler) AddFloatArg(aliases []string, doc string) error
Add a float argument to the subcommand. Warning, the subcommand will always fail if the argument is not set. If one of the aliases is used by another argument or parameter, the function will return an error and handler will not be mutated.
func (*SubcommandHandler) AddFloatParamWithDefault ¶
func (h *SubcommandHandler) AddFloatParamWithDefault(aliases []string, doc string, deflt float64) error
Add a float parameter to the subcommand with a default value.
func (*SubcommandHandler) AddIntArg ¶
func (h *SubcommandHandler) AddIntArg(aliases []string, doc string) error
Add an integer argument to the subcommand. Warning, the subcommand will always fail if the argument is not set. If one of the aliases is used by another argument or parameter, the function will return an error and handler will not be mutated.
func (*SubcommandHandler) AddIntParamWithDefault ¶
func (h *SubcommandHandler) AddIntParamWithDefault(aliases []string, doc string, deflt int) error
Add an integer parameter to the subcommand with a default value.
func (*SubcommandHandler) AddStrArg ¶
func (h *SubcommandHandler) AddStrArg(aliases []string, doc string) error
Add a string argument to the subcommand. Warning, the subcommand will always fail if the argument is not set. If one of the aliases is used by another argument or parameter, the function will return an error and handler will not be mutated.
func (*SubcommandHandler) AddStrParamWithDefault ¶
func (h *SubcommandHandler) AddStrParamWithDefault(aliases []string, doc string, deflt string) error
Add string parameter to the subcommand with a default value.
func (*SubcommandHandler) Example ¶
func (h *SubcommandHandler) Example(doc string, cmd string, out string)
Add an example to a SubcommandHandler instance. The argument `doc` is documentation for the example. The argument `cmd` is the text of the command with command line arguments. The argument `out` is the plausible output for the command
func (*SubcommandHandler) GetBool ¶
func (h *SubcommandHandler) GetBool(key string) (val bool, err error)
Get a string argument or parameter from the command line. Warning: This function will fail if the command line arguments have not already been parsed.
func (*SubcommandHandler) GetFloat ¶
func (h *SubcommandHandler) GetFloat(key string) (float64, error)
Get a string argument or parameter from the command line. Warning: This function will fail if the command line arguments have not already been parsed.
func (*SubcommandHandler) GetInt ¶
func (h *SubcommandHandler) GetInt(key string) (int, error)
Get an integer argument or parameter from the command line. Warning: This function will fail if the command line arguments have not already been parsed.
func (*SubcommandHandler) GetStr ¶
func (h *SubcommandHandler) GetStr(key string) (string, error)
Get a string argument or parameter from the command line. Warning: This function will fail if the command line arguments have not already been parsed.
func (*SubcommandHandler) Handle ¶
func (h *SubcommandHandler) Handle(f func(insub *SubcommandHandler))
Set the handler function for a SubcommandHandler instance. # Arguments - sub: a SubcommandHandler instance to be mutated - f: the handler function