Documentation ¶
Index ¶
- type ArgParseResult
- type Argument
- type Command
- func (c *Command) AddFlag(name, shortName, desc string) *Flag
- func (c *Command) AddFloatArg(name, shortName, desc string, required bool) *FloatArgument
- func (c *Command) AddIntArg(name, shortName, desc string, required bool) *IntArgument
- func (c *Command) AddPrimaryArg(name, desc string, required bool) *PrimaryArgument
- func (c *Command) AddSelectorArg(name, shortName, desc string, required bool, possibleValues []string) *SelectorArgument
- func (c *Command) AddStringArg(name, shortName, desc string, required bool) *StringArgument
- func (c *Command) AddSubcommand(name, desc string, helpEnabled bool) *Command
- func (c *Command) DisableHelp()
- func (c *Command) EnableHelp()
- func (c *Command) Help()
- func (c *Command) HelpMessage() string
- type Flag
- type FloatArgument
- func (ab *FloatArgument) Description() string
- func (ab *FloatArgument) GetDefaultValue() (interface{}, bool)
- func (ab *FloatArgument) Name() string
- func (ab *FloatArgument) Required() bool
- func (fa *FloatArgument) SetDefaultValue(v float64)
- func (fa *FloatArgument) SetValidator(v func(float64) error)
- func (ab *FloatArgument) ShortName() string
- type IntArgument
- func (ab *IntArgument) Description() string
- func (ab *IntArgument) GetDefaultValue() (interface{}, bool)
- func (ab *IntArgument) Name() string
- func (ab *IntArgument) Required() bool
- func (ia *IntArgument) SetDefaultValue(v int)
- func (ia *IntArgument) SetValidator(v func(int) error)
- func (ab *IntArgument) ShortName() string
- type PrimaryArgument
- type SelectorArgument
- func (ab *SelectorArgument) Description() string
- func (ab *SelectorArgument) GetDefaultValue() (interface{}, bool)
- func (ab *SelectorArgument) Name() string
- func (ab *SelectorArgument) Required() bool
- func (sea *SelectorArgument) SetDefaultValue(v string)
- func (sea *SelectorArgument) SetValidator(v func(string) error)
- func (ab *SelectorArgument) ShortName() string
- type StringArgument
- func (ab *StringArgument) Description() string
- func (ab *StringArgument) GetDefaultValue() (interface{}, bool)
- func (ab *StringArgument) Name() string
- func (ab *StringArgument) Required() bool
- func (sa *StringArgument) SetDefaultValue(v string)
- func (sa *StringArgument) SetValidator(v func(string) error)
- func (ab *StringArgument) ShortName() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgParseResult ¶
type ArgParseResult struct { Arguments map[string]interface{} // contains filtered or unexported fields }
ArgParseResult is the result produced by the argument parser representing the inputted arguments if parsing succeeded.
func ParseArgs ¶
func ParseArgs(cli *Command, args []string) (*ArgParseResult, error)
ParseArgs parses the slice of arguments provided against a customized CLI. It returns an ArgParseResult representing the accumulated result of parsing and an error which will be `nil` if no error occured
func (*ArgParseResult) HasFlag ¶
func (apr *ArgParseResult) HasFlag(name string) bool
HasFlag checks if a flag has been set during argument parsing
func (*ArgParseResult) PrimaryArg ¶
func (apr *ArgParseResult) PrimaryArg() (string, bool)
PrimaryArg gets the primary argument if one exists
func (*ArgParseResult) Subcommand ¶
func (apr *ArgParseResult) Subcommand() (string, *ArgParseResult, bool)
Subcommand gets the subcommand if one exists
type Argument ¶
type Argument interface { // Name gives the full name of the argument Name() string // ShortName gives the short name of the argument ShortName() string // Description returns the description of the argument Description() string // Required indicates whether or not the argument is required Required() bool // GetDefaultValue gets the default value of the argument GetDefaultValue() (interface{}, bool) // contains filtered or unexported methods }
Argument represents a value that can be passed to the application via a label (eg. `--loglevel=silent`). There are many different kinds of arguments and so this is an interface to allow for sub-arguments
type Command ¶
type Command struct { // Name is the name of the command Name string // Description is a descriptive string for the command Description string // Requires subcommand indicates if this command expects a subcommand or can // be satisfied without one RequiresSubcommand bool // contains filtered or unexported fields }
Command represents a keyword which determines the state of the parser and how it should continue to parse: it is a directive or subdirective to the application. (eg. `go build` has a command of `go` and a subcommand of `build`).
func (*Command) AddFloatArg ¶
func (c *Command) AddFloatArg(name, shortName, desc string, required bool) *FloatArgument
AddFloatArg adds a named float argument
func (*Command) AddIntArg ¶
func (c *Command) AddIntArg(name, shortName, desc string, required bool) *IntArgument
AddIntArg adds a named integer argument
func (*Command) AddPrimaryArg ¶
func (c *Command) AddPrimaryArg(name, desc string, required bool) *PrimaryArgument
AddPrimaryArg adds a primary argument to the command
func (*Command) AddSelectorArg ¶
func (c *Command) AddSelectorArg(name, shortName, desc string, required bool, possibleValues []string) *SelectorArgument
AddSelectorArg adds a named selector argument
func (*Command) AddStringArg ¶
func (c *Command) AddStringArg(name, shortName, desc string, required bool) *StringArgument
AddStringArg adds a named string argument
func (*Command) AddSubcommand ¶
AddSubcommand adds a subcommand to the command
func (*Command) DisableHelp ¶
func (c *Command) DisableHelp()
DisableHelp disables the help flag (`--help` or `-h`).
func (*Command) EnableHelp ¶
func (c *Command) EnableHelp()
EnableHelp enables the help flag (`--help` or `-h`).
func (*Command) HelpMessage ¶
HelpMessage returns the stringified help message for a given command
type Flag ¶
type Flag struct {
// contains filtered or unexported fields
}
Flag represents a flag that when encountered stores true
func (*Flag) Description ¶
Description gets the description of the flag
type FloatArgument ¶
type FloatArgument struct {
// contains filtered or unexported fields
}
FloatArgument is an argument whose value must be a float
func (*FloatArgument) Description ¶
func (ab *FloatArgument) Description() string
func (*FloatArgument) GetDefaultValue ¶
func (ab *FloatArgument) GetDefaultValue() (interface{}, bool)
func (*FloatArgument) SetDefaultValue ¶
func (fa *FloatArgument) SetDefaultValue(v float64)
SetDefaultValue sets the default value of this argument
func (*FloatArgument) SetValidator ¶
func (fa *FloatArgument) SetValidator(v func(float64) error)
SetValidator sets a validation function for this argument
type IntArgument ¶
type IntArgument struct {
// contains filtered or unexported fields
}
IntArgument is an argument whose value must be an integer
func (*IntArgument) Description ¶
func (ab *IntArgument) Description() string
func (*IntArgument) GetDefaultValue ¶
func (ab *IntArgument) GetDefaultValue() (interface{}, bool)
func (*IntArgument) SetDefaultValue ¶
func (ia *IntArgument) SetDefaultValue(v int)
SetDefaultValue sets the default value of this argument
func (*IntArgument) SetValidator ¶
func (ia *IntArgument) SetValidator(v func(int) error)
SetValidator sets a validation function for this argument
type PrimaryArgument ¶
type PrimaryArgument struct {
// contains filtered or unexported fields
}
PrimaryArgument is an argument that is passed to command without an explicit label (eg. for `go build <filename>`, `<filename>` is the primary argument). Note that a command cannot both take a primary argument and subcommands.
func (*PrimaryArgument) Description ¶
func (pa *PrimaryArgument) Description() string
Description returns the description of the primary argument
func (*PrimaryArgument) Name ¶
func (pa *PrimaryArgument) Name() string
Name returns the name of the primary argument
func (*PrimaryArgument) Required ¶
func (pa *PrimaryArgument) Required() bool
Required indicates whether or not this argument must be supplied
type SelectorArgument ¶
type SelectorArgument struct {
// contains filtered or unexported fields
}
SelectorArgument is an argument whose value is constained to a finite set of string values
func (*SelectorArgument) Description ¶
func (ab *SelectorArgument) Description() string
func (*SelectorArgument) GetDefaultValue ¶
func (ab *SelectorArgument) GetDefaultValue() (interface{}, bool)
func (*SelectorArgument) SetDefaultValue ¶
func (sea *SelectorArgument) SetDefaultValue(v string)
SetDefaultValue sets the default value of this argument
func (*SelectorArgument) SetValidator ¶
func (sea *SelectorArgument) SetValidator(v func(string) error)
SetValidator sets a validation function for this argument
type StringArgument ¶
type StringArgument struct {
// contains filtered or unexported fields
}
StringArgument is an argument whose value must be a string
func (*StringArgument) Description ¶
func (ab *StringArgument) Description() string
func (*StringArgument) GetDefaultValue ¶
func (ab *StringArgument) GetDefaultValue() (interface{}, bool)
func (*StringArgument) SetDefaultValue ¶
func (sa *StringArgument) SetDefaultValue(v string)
SetDefaultValue sets the default value of this argument
func (*StringArgument) SetValidator ¶
func (sa *StringArgument) SetValidator(v func(string) error)
SetValidator sets a validation function for this argument