Documentation
¶
Overview ¶
Package argparser provides command line argument parsing for implementing commands that behave like the standard unix shell.
Index ¶
- Variables
- type ArgParseResults
- func (res *ArgParseResults) AnyFlagsEqualTo(val bool) *set.StrSet
- func (res *ArgParseResults) Arg(idx int) string
- func (res *ArgParseResults) Contains(name string) bool
- func (res *ArgParseResults) ContainsAll(names ...string) bool
- func (res *ArgParseResults) ContainsAny(names ...string) bool
- func (res *ArgParseResults) ContainsArg(name string) bool
- func (res *ArgParseResults) ContainsMany(names ...string) []string
- func (res *ArgParseResults) Equals(other *ArgParseResults) bool
- func (res *ArgParseResults) FlagsEqualTo(names []string, val bool) *set.StrSet
- func (res *ArgParseResults) GetInt(name string) (int, bool)
- func (res *ArgParseResults) GetIntOrDefault(name string, defVal int) int
- func (res *ArgParseResults) GetUint(name string) (uint64, bool)
- func (res *ArgParseResults) GetValue(name string) (string, bool)
- func (res *ArgParseResults) GetValueOrDefault(name, defVal string) string
- func (res *ArgParseResults) GetValues(names ...string) map[string]string
- func (res *ArgParseResults) MustGetValue(name string) string
- func (res *ArgParseResults) NArg() int
- type ArgParser
- func (ap *ArgParser) Parse(args []string) (*ArgParseResults, error)
- func (ap *ArgParser) SupportOption(opt *Option)
- func (ap *ArgParser) SupportsFlag(name, abbrev, desc string) *ArgParser
- func (ap *ArgParser) SupportsInt(name, abbrev, valDesc, desc string) *ArgParser
- func (ap *ArgParser) SupportsString(name, abbrev, valDesc, desc string) *ArgParser
- func (ap *ArgParser) SupportsUint(name, abbrev, valDesc, desc string) *ArgParser
- func (ap *ArgParser) SupportsValidatedString(name, abbrev, valDesc, desc string, validator ValidationFunc) *ArgParser
- type Option
- type OptionType
- type UnknownArgumentParam
- type ValidationFunc
Constants ¶
This section is empty.
Variables ¶
var ErrHelp = errors.New("Help")
Functions ¶
This section is empty.
Types ¶
type ArgParseResults ¶
type ArgParseResults struct { Args []string // contains filtered or unexported fields }
func (*ArgParseResults) AnyFlagsEqualTo ¶
func (res *ArgParseResults) AnyFlagsEqualTo(val bool) *set.StrSet
func (*ArgParseResults) Arg ¶
func (res *ArgParseResults) Arg(idx int) string
func (*ArgParseResults) Contains ¶
func (res *ArgParseResults) Contains(name string) bool
func (*ArgParseResults) ContainsAll ¶
func (res *ArgParseResults) ContainsAll(names ...string) bool
func (*ArgParseResults) ContainsAny ¶
func (res *ArgParseResults) ContainsAny(names ...string) bool
func (*ArgParseResults) ContainsArg ¶
func (res *ArgParseResults) ContainsArg(name string) bool
func (*ArgParseResults) ContainsMany ¶
func (res *ArgParseResults) ContainsMany(names ...string) []string
func (*ArgParseResults) Equals ¶
func (res *ArgParseResults) Equals(other *ArgParseResults) bool
func (*ArgParseResults) FlagsEqualTo ¶
func (res *ArgParseResults) FlagsEqualTo(names []string, val bool) *set.StrSet
func (*ArgParseResults) GetIntOrDefault ¶
func (res *ArgParseResults) GetIntOrDefault(name string, defVal int) int
func (*ArgParseResults) GetValueOrDefault ¶
func (res *ArgParseResults) GetValueOrDefault(name, defVal string) string
func (*ArgParseResults) GetValues ¶
func (res *ArgParseResults) GetValues(names ...string) map[string]string
func (*ArgParseResults) MustGetValue ¶
func (res *ArgParseResults) MustGetValue(name string) string
func (*ArgParseResults) NArg ¶
func (res *ArgParseResults) NArg() int
type ArgParser ¶
type ArgParser struct { Supported []*Option NameOrAbbrevToOpt map[string]*Option ArgListHelp [][2]string }
func NewArgParser ¶
func NewArgParser() *ArgParser
func (*ArgParser) Parse ¶
func (ap *ArgParser) Parse(args []string) (*ArgParseResults, error)
Parses the string args given using the configuration previously specified with calls to the various Supports* methods. Any unrecognized arguments or incorrect types will result in an appropriate error being returned. If the universal --help or -h flag is found, an ErrHelp error is returned.
func (*ArgParser) SupportOption ¶
Adds support for a new argument with the option given. Options must have a unique name and abbreviated name.
func (*ArgParser) SupportsFlag ¶
Adds support for a new flag (argument with no value). See SupportOpt for details on params.
func (*ArgParser) SupportsInt ¶
Adds support for a new int argument with the description given. See SupportOpt for details on params.
func (*ArgParser) SupportsString ¶
Adds support for a new string argument with the description given. See SupportOpt for details on params.
func (*ArgParser) SupportsUint ¶
Adds support for a new uint argument with the description given. See SupportOpt for details on params.
func (*ArgParser) SupportsValidatedString ¶
func (ap *ArgParser) SupportsValidatedString(name, abbrev, valDesc, desc string, validator ValidationFunc) *ArgParser
type Option ¶
type Option struct { // Long name for this Option, specified on the command line with --Name. Required. Name string // Abbreviated name for this Option, specified on the command line with -Abbrev. Optional. Abbrev string // Brief description of the Option. ValDesc string // The type of this option, either a flag or a value. OptType OptionType // Longer help text for the option. Desc string // Function to validate an Option after parsing, returning any error. Validator ValidationFunc }
An Option encapsulates all the information necessary to represent and parse a command line argument.
type UnknownArgumentParam ¶
type UnknownArgumentParam struct {
// contains filtered or unexported fields
}
func (UnknownArgumentParam) Error ¶
func (unkn UnknownArgumentParam) Error() string
type ValidationFunc ¶
func ValidatorFromStrList ¶
func ValidatorFromStrList(paramName string, validStrList []string) ValidationFunc