arg

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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 Arg

type Arg struct {
	// contains filtered or unexported fields
}

func (*Arg) DefValue

func (a *Arg) DefValue() string

func (*Arg) Describe

func (a *Arg) Describe(kind string, hint string) string

func (*Arg) Name

func (a *Arg) Name() string

func (*Arg) Usage

func (a *Arg) Usage() string

func (*Arg) Value

func (a *Arg) Value() interface{}

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 All

func All(into *[]string, name string, usage string) *ArgSet

All provides an ArgSet that collects all of the arguments into a slice of strings.

func NewArgSet

func NewArgSet() *ArgSet

func (*ArgSet) Bool

func (a *ArgSet) Bool(p *bool, name string, usage string)

func (*ArgSet) BoolOptional

func (a *ArgSet) BoolOptional(p *bool, name string, value bool, usage string)

func (*ArgSet) Duration

func (a *ArgSet) Duration(p *time.Duration, name string, usage string)

func (*ArgSet) DurationOptional

func (a *ArgSet) DurationOptional(p *time.Duration, name string, value time.Duration, usage string)

func (*ArgSet) Float64

func (a *ArgSet) Float64(p *float64, name string, usage string)

func (*ArgSet) Float64Optional

func (a *ArgSet) Float64Optional(p *float64, name string, value float64, usage string)

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) Int

func (a *ArgSet) Int(p *int, name string, usage string)

func (*ArgSet) Int64

func (a *ArgSet) Int64(p *int64, name string, usage string)

func (*ArgSet) Int64Optional

func (a *ArgSet) Int64Optional(p *int64, name string, value int64, usage string)

func (*ArgSet) IntOptional

func (a *ArgSet) IntOptional(p *int, name string, value int, usage string)

func (*ArgSet) Invocation

func (a *ArgSet) Invocation() string

Invocation returns an example command invocation string intended for display in the "Usage:" section of a command's help message.

func (*ArgSet) NArg

func (a *ArgSet) NArg() int

NArg returns the number of args that have been defined. A "remaining" arg counts as one arg.

func (*ArgSet) Parse

func (a *ArgSet) Parse(input []string) error

func (*ArgSet) Remaining

func (a *ArgSet) Remaining(p *[]string, name string, minmax Range, usage string)

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

func (a *ArgSet) RemainingFloat64s(p *[]float64, name string, minmax Range, usage string)

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

func (a *ArgSet) RemainingInt64s(p *[]int64, name string, minmax Range, usage string)

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

func (a *ArgSet) RemainingInts(p *[]int, name string, minmax Range, usage string)

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

func (a *ArgSet) RemainingUint64s(p *[]uint64, name string, minmax Range, usage string)

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

func (a *ArgSet) RemainingUints(p *[]uint, name string, minmax Range, usage string)

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

func (a *ArgSet) RemainingVar(val ArgVal, name string, minmax Range, usage string)

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) String

func (a *ArgSet) String(p *string, name string, usage string)

func (*ArgSet) StringOptional

func (a *ArgSet) StringOptional(p *string, name string, value string, usage string)

func (*ArgSet) Uint

func (a *ArgSet) Uint(p *uint, name string, usage string)

func (*ArgSet) Uint64

func (a *ArgSet) Uint64(p *uint64, name string, usage string)

func (*ArgSet) Uint64Optional

func (a *ArgSet) Uint64Optional(p *uint64, name string, value uint64, usage string)

func (*ArgSet) UintOptional

func (a *ArgSet) UintOptional(p *uint, name string, value uint, usage string)

func (*ArgSet) Usage

func (a *ArgSet) Usage() string

func (*ArgSet) Var

func (a *ArgSet) Var(val ArgVal, name string, usage string)

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 ArgVal

type ArgVal interface {
	Set(string) error
	String() string
}

ArgVal is exactly the same as flag.Value and should be 100% compatible.

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 Int64List

type Int64List []int64

func (*Int64List) Get

func (i *Int64List) Get() interface{}

func (Int64List) Ints

func (i Int64List) Ints() []int64

func (*Int64List) Set

func (i *Int64List) Set(s string) error

func (*Int64List) String

func (i *Int64List) String() string

type IntList

type IntList []int

func (*IntList) Get

func (i *IntList) Get() interface{}

func (IntList) Ints

func (i IntList) Ints() []int

func (*IntList) Set

func (i *IntList) Set(s string) error

func (*IntList) String

func (i *IntList) 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

func Max(max int) Range

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

func Min(min int) Range

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

func MinMax(min, max int) Range

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

type UintList

type UintList []uint

func (*UintList) Get

func (i *UintList) Get() interface{}

func (*UintList) Set

func (i *UintList) Set(s string) error

func (*UintList) String

func (i *UintList) String() string

func (UintList) Uints

func (i UintList) Uints() []uint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL