Documentation ¶
Overview ¶
Package flags is a low level package for parsing or managing single flag arguments and their associated values from an argument list. It's useful for CLI applications or creating logic for parsing arguments(custom or os.Args) manually.
Index ¶
- func Exclude(flagName string, args []string) []string
- func Has(name string, args []string) bool
- func IntSlice(value []int, name, usage string) *[]int
- func IntSliceVar(p *[]int, value []int, name, usage string)
- func Parse(arg string) (string, error)
- func StringSlice(value []string, name, usage string) *[]string
- func StringSliceVar(p *[]string, value []string, name, usage string)
- func Valid(arg string) bool
- func Value(flagName string, args []string) (string, error)
- type IntSliceValue
- type StringSliceValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exclude ¶
Exclude excludes/removes the given valid flagName with it's associated value (or none) from the args. It returns the remaining arguments. If no flagName is passed or if the flagName is invalid, remaining arguments are returned without any change.
func IntSlice ¶
IntSlice defines a []int flag with specified name, default value, and usage string. The return value is the address of a []int variable that stores the value of the flag.
func IntSliceVar ¶
IntSliceVar defines a []int flag with specified name, default value, and usage string. The argument p points to a []int variable in which to store the value of the flag.
func Parse ¶
Parse parses a flags name. A flag can be in form of --name=value, -name=value, or a boolean flag --name, -name=, etc... If it's a correct flag, the name is returned. If not an empty string and an error message is returned.
func StringSlice ¶
StringSlice defines a []string flag with specified name, default value, and usage string. The return value is the address of a []string variable that stores the value of the flag.
func StringSliceVar ¶
StringSliceVar defines a []string flag with specified name, default value, and usage string. The argument p points to a []string variable in which to store the value of the flag.
func Value ¶
Value parses the given flagName from the args slice and returns the value passed to the flag. An example: args: ["--provider", "aws"] will return "aws" for the flag name "provider". An empty string and non error means the flag is in the boolean form, i.e: ["--provider", "--foo", "bar], will return "" as value for the flag name "provider.
Types ¶
type IntSliceValue ¶
type IntSliceValue []int
func NewIntSlice ¶
func NewIntSlice(val []int, p *[]int) *IntSliceValue
NewIntSlice returns a new IntSlice which satisfies the flag.Value interface. This is useful to be used with flag.FlagSet. For the global flag instance, IntSlice() and IntSliceVar() can be used.
func (*IntSliceValue) Get ¶
func (i *IntSliceValue) Get() interface{}
func (*IntSliceValue) Set ¶
func (i *IntSliceValue) Set(val string) error
func (*IntSliceValue) String ¶
func (i *IntSliceValue) String() string
type StringSliceValue ¶
type StringSliceValue []string
func NewStringSlice ¶
func NewStringSlice(val []string, p *[]string) *StringSliceValue
NewStringSlice returns a new StringSlice which satisfies the flag.Value interface. This is useful to be used with flag.FlagSet. For the global flag instance, StringSlice() and StringSliceVar() can be used.
func (*StringSliceValue) Get ¶
func (s *StringSliceValue) Get() interface{}
func (*StringSliceValue) Set ¶
func (s *StringSliceValue) Set(val string) error
func (*StringSliceValue) String ¶
func (s *StringSliceValue) String() string