Documentation ¶
Index ¶
- Constants
- Variables
- type Arg
- type ArgGetter
- type ArgSet
- func (a *ArgSet) Bool(p *bool, name string, usage string)
- func (a *ArgSet) BoolOptional(p *bool, name string, value bool, usage string)
- func (a *ArgSet) Duration(p *time.Duration, name string, usage string)
- func (a *ArgSet) DurationOptional(p *time.Duration, name string, value time.Duration, usage string)
- func (a *ArgSet) Float64(p *float64, name string, usage string)
- func (a *ArgSet) Float64Optional(p *float64, name string, value float64, usage string)
- func (a *ArgSet) HideUsage()
- func (a *ArgSet) Int(p *int, name string, usage string)
- func (a *ArgSet) Int64(p *int64, name string, usage string)
- func (a *ArgSet) Int64Optional(p *int64, name string, value int64, usage string)
- func (a *ArgSet) IntOptional(p *int, name string, value int, usage string)
- func (a *ArgSet) Invocation() string
- func (a *ArgSet) NArg() int
- func (a *ArgSet) Parse(input []string) error
- func (a *ArgSet) Remaining(p *[]string, name string, minmax Range, usage string)
- func (a *ArgSet) RemainingFloat64s(p *[]float64, name string, minmax Range, usage string)
- func (a *ArgSet) RemainingInt64s(p *[]int64, name string, minmax Range, usage string)
- func (a *ArgSet) RemainingInts(p *[]int, name string, minmax Range, usage string)
- func (a *ArgSet) RemainingUint64s(p *[]uint64, name string, minmax Range, usage string)
- func (a *ArgSet) RemainingUints(p *[]uint, name string, minmax Range, usage string)
- func (a *ArgSet) RemainingVar(val ArgVal, name string, minmax Range, usage string)
- func (a *ArgSet) String(p *string, name string, usage string)
- func (a *ArgSet) StringOptional(p *string, name string, value string, usage string)
- func (a *ArgSet) Uint(p *uint, name string, usage string)
- func (a *ArgSet) Uint64(p *uint64, name string, usage string)
- func (a *ArgSet) Uint64Optional(p *uint64, name string, value uint64, usage string)
- func (a *ArgSet) UintOptional(p *uint, name string, value uint, usage string)
- func (a *ArgSet) Usage() string
- func (a *ArgSet) Var(val ArgVal, name string, usage string)
- type ArgVal
- type Float64List
- type Int64List
- type IntList
- type Range
- type StringList
- type Uint64List
- type UintList
Constants ¶
const Unlimited = -1
Unlimited is a sentinel value used for the Max of a Range to indicate that it is unbounded.
FIXME: This could probably be set to 0; why would you specify a Remaining Arg that had a Max of 0 when you could just not specify the Remaining arg at all?
Variables ¶
var AnyLen = Range{0, Unlimited}
AnyLen is used for a Remaining arg that can take 0 or more arguments.
var strs []string argSet.Remaining(&strs, "strs", arg.AnyLen, "All remaining string arguments")
Functions ¶
This section is empty.
Types ¶
type ArgGetter ¶
type ArgGetter interface { ArgVal Get() interface{} }
ArgGetter is exactly the same as flag.Getter and should be 100% compatible.
type ArgSet ¶
type ArgSet struct {
// contains filtered or unexported fields
}
An ArgSet represents a set of defined command-line arguments. It is intended to mirror, as closely as reasonable, the structure of the flag.FlagSet package in the Go standard library.
func (*ArgSet) BoolOptional ¶
func (*ArgSet) DurationOptional ¶
func (*ArgSet) Float64Optional ¶
func (*ArgSet) HideUsage ¶
func (a *ArgSet) HideUsage()
HideUsage prevents the Usage string for the ArgSet being built. It is primarily intended to help if you have a dynamic subcommand dispatch and don't want spurious and redundant usage documentation for things like "Usage: <command> <args>...".
func (*ArgSet) Int64Optional ¶
func (*ArgSet) IntOptional ¶
func (*ArgSet) Invocation ¶
Invocation returns an example command invocation string intended for display in the "Usage:" section of a command's help message.
func (*ArgSet) NArg ¶
NArg returns the number of args that have been defined. A "remaining" arg counts as one arg.
func (*ArgSet) Remaining ¶
Remaining collects all args after the last defined argument into the slice of strings pointed to by p. If more args are defined after any Remaining method is called, args will panic.
Use arg.AnyLen to allow an arbitrary number of remaining args. Use arg.Min(2) to require at least 2 args. Use arg.Max(2) to require at most 2 args. Use arg.MinMax(1, 3) to require at least 1 arg and at most 3 args.
func (*ArgSet) RemainingFloat64s ¶
RemainingFloat64s collects all args after the last defined argument into the slice of float64s pointed to by p. If more args are defined after any Remaining method is called, args will panic.
See Remaining for an explanation of minmax and usage.
func (*ArgSet) RemainingInt64s ¶
RemainingInt64s collects all args after the last defined argument into the slice of int64s pointed to by p. If more args are defined after any Remaining method is called, args will panic.
See Remaining for an explanation of minmax and usage.
func (*ArgSet) RemainingInts ¶
RemainingInts collects all args after the last defined argument into the slice of ints pointed to by p. If more args are defined after any Remaining method is called, args will panic.
See Remaining for an explanation of minmax and usage.
func (*ArgSet) RemainingUint64s ¶
RemainingUint64s collects all args after the last defined argument into the slice of uint64s pointed to by p. If more args are defined after any Remaining method is called, args will panic.
See Remaining for an explanation of minmax and usage.
func (*ArgSet) RemainingUints ¶
RemainingInt64s collects all args after the last defined argument into the slice of int64s pointed to by p. If more args are defined after any Remaining method is called, args will panic.
See Remaining for an explanation of minmax and usage.
func (*ArgSet) RemainingVar ¶
RemainingVar collects all args after the last defined argument into the slice of ArgVals pointed to by p. If more args are defined after any Remaining method is called, args will panic.
See Remaining for an explanation of minmax and usage.
func (*ArgSet) StringOptional ¶
func (*ArgSet) Uint64Optional ¶
func (*ArgSet) UintOptional ¶
func (*ArgSet) Var ¶
Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type ArgVal, which typically holds a user-defined implementation of ArgVal. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of ArgVal; in particular, Set would decompose the comma-separated string into the slice.
ArgVal is 100% compatible with the flag.Getter interface from the Go standard library; anything that can be used by flag.FlagSet.Var can be used by arg.ArgSet.Var with no modification.
type Float64List ¶
type Float64List []float64
func (Float64List) Float64s ¶
func (i Float64List) Float64s() []float64
func (*Float64List) Get ¶
func (i *Float64List) Get() interface{}
func (*Float64List) Set ¶
func (i *Float64List) Set(s string) error
func (*Float64List) String ¶
func (i *Float64List) String() string
type Range ¶
type Range struct { Min int // Inclusive upper bound for this range; set to Unlimited for no limit. Max int }
func Max ¶
Max is used to place an upper bound on the number of values allowed for a Remaining arg.
In the following example, the args will pass validation if there are 2 or fewer:
argSet.Remaining(&strs, "strs", arg.Max(2), "Remaining strings") $ myprog // valid $ myprog a // valid $ myprog a b // valid $ myprog a b c // invalid
func Min ¶
Min is used to place a lower bound on the number of values required for a Remaining arg.
In the following example, the args will pass validation if there are 2 or more:
argSet.Remaining(&strs, "strs", arg.Min(2), "Remaining strings") $ myprog // invalid $ myprog a // invalid $ myprog a b // valid $ myprog a b c // valid
func MinMax ¶
MinMax is used to place an upper and lower bound on the number of values allowed for a Remaining arg.
In the following example, the args will pass validation if there are between 2 and 4 args inclusive:
argSet.Remaining(&strs, "strs", arg.MinMax(2, 4), "Remaining strings") $ myprog a // invalid $ myprog a b // valid $ myprog a b c // valid $ myprog a b c d // valid $ myprog a b c d e // invalid
type StringList ¶
type StringList []string
func (*StringList) Get ¶
func (s *StringList) Get() interface{}
func (*StringList) Set ¶
func (s *StringList) Set(v string) error
func (*StringList) String ¶
func (s *StringList) String() string
func (StringList) Strings ¶
func (s StringList) Strings() []string
type Uint64List ¶
type Uint64List []uint64
func (*Uint64List) Get ¶
func (i *Uint64List) Get() interface{}
func (*Uint64List) Set ¶
func (i *Uint64List) Set(s string) error
func (*Uint64List) String ¶
func (i *Uint64List) String() string
func (Uint64List) Uints ¶
func (i Uint64List) Uints() []uint64