Documentation
¶
Index ¶
- Variables
- type ErrorHandling
- type Extractor
- type FileSource
- type Flag
- type FlagSet
- func (fs *FlagSet) Arg(i int) string
- func (fs *FlagSet) Args() []string
- func (fs *FlagSet) Bool(name string, usage string, extractors ...Extractor) *bool
- func (fs *FlagSet) BoolVar(v *bool, name string, usage string, extractors ...Extractor)
- func (fs *FlagSet) Description() string
- func (fs *FlagSet) Duration(name string, defaultValue time.Duration, usage string, extractors ...Extractor) *time.Duration
- func (fs *FlagSet) DurationList(name string, defaultValue []time.Duration, usage string, ...) *[]time.Duration
- func (fs *FlagSet) DurationListVar(v *[]time.Duration, name string, defaultValue []time.Duration, usage string, ...)
- func (fs *FlagSet) DurationVar(v *time.Duration, name string, defaultValue time.Duration, usage string, ...)
- func (fs *FlagSet) Float(name string, defaultValue float64, usage string, extractors ...Extractor) *float64
- func (fs *FlagSet) FloatList(name string, defaultValue []float64, usage string, extractors ...Extractor) *[]float64
- func (fs *FlagSet) FloatListVar(v *[]float64, name string, defaultValue []float64, usage string, ...)
- func (fs *FlagSet) FloatVar(v *float64, name string, defaultValue float64, usage string, ...)
- func (fs *FlagSet) Init(name, description string, errorHandling ErrorHandling)
- func (fs *FlagSet) Int(name string, defaultValue int, usage string, extractors ...Extractor) *int
- func (fs *FlagSet) Int64(name string, defaultValue int64, usage string, extractors ...Extractor) *int64
- func (fs *FlagSet) Int64List(name string, defaultValue []int64, usage string, extractors ...Extractor) *[]int64
- func (fs *FlagSet) Int64ListVar(v *[]int64, name string, defaultValue []int64, usage string, ...)
- func (fs *FlagSet) Int64Var(v *int64, name string, defaultValue int64, usage string, ...)
- func (fs *FlagSet) IntList(name string, defaultValue []int, usage string, extractors ...Extractor) *[]int
- func (fs *FlagSet) IntListVar(v *[]int, name string, defaultValue []int, usage string, ...)
- func (fs *FlagSet) IntVar(v *int, name string, defaultValue int, usage string, extractors ...Extractor)
- func (fs *FlagSet) Lookup(name string) *Flag
- func (fs *FlagSet) NArg() int
- func (fs *FlagSet) NFlags() int
- func (fs *FlagSet) Name() string
- func (fs *FlagSet) Output() io.Writer
- func (fs *FlagSet) Parse(args []string, sources ...Source) error
- func (fs *FlagSet) Parsed() bool
- func (fs *FlagSet) PrintDefaults()
- func (fs *FlagSet) SetOutput(w io.Writer)
- func (fs *FlagSet) String(name, defaultValue, usage string, extractors ...Extractor) *string
- func (fs *FlagSet) StringList(name string, defaultValue []string, usage string, extractors ...Extractor) *[]string
- func (fs *FlagSet) StringListVar(v *[]string, name string, defaultValue []string, usage string, ...)
- func (fs *FlagSet) StringVar(v *string, name string, defaultValue string, usage string, ...)
- func (fs *FlagSet) Uint(name string, defaultValue uint, usage string, extractors ...Extractor) *uint
- func (fs *FlagSet) Uint64(name string, defaultValue uint64, usage string, extractors ...Extractor) *uint64
- func (fs *FlagSet) Uint64List(name string, defaultValue []uint64, usage string, extractors ...Extractor) *[]uint64
- func (fs *FlagSet) Uint64ListVar(v *[]uint64, name string, defaultValue []uint64, usage string, ...)
- func (fs *FlagSet) Uint64Var(v *uint64, name string, defaultValue uint64, usage string, ...)
- func (fs *FlagSet) UintList(name string, defaultValue []uint, usage string, extractors ...Extractor) *[]uint
- func (fs *FlagSet) UintListVar(v *[]uint, name string, defaultValue []uint, usage string, ...)
- func (fs *FlagSet) UintVar(v *uint, name string, defaultValue uint, usage string, extractors ...Extractor)
- type ParseFunc
- type Source
- type Value
Constants ¶
This section is empty.
Variables ¶
var ErrHelp = fmt.Errorf("flagga: help requested")
ErrHelp is returned when -h, --h, --help or -help are found.
Functions ¶
This section is empty.
Types ¶
type ErrorHandling ¶
type ErrorHandling byte
ErrorHandling defines what happens if an error is encountered while parsing a flag set.
const ( // ContinueOnError will not halt the program if an error is encountered. ContinueOnError ErrorHandling = iota // ExitOnError will call os.Exit(2) after encountering an error. ExitOnError // PanicOnError will panic after encountering an error. PanicOnError )
type Extractor ¶
type Extractor interface {
// Get checks the sources and tries to assign the flag value.
Get(sources []Source, dst Value) (bool, error)
}
Extractor extracts values from the sources to fill the flag value.
type FileSource ¶
FileSource is a Source that reads a file and parses it using a parser function.
func (*FileSource) Close ¶
func (s *FileSource) Close() error
Close implements the Source interface.
type Flag ¶
type Flag struct {
Name string
Usage string
Value Value
Default interface{}
Extractors []Extractor
}
Flag is a single flag in the program.
type FlagSet ¶
type FlagSet struct {
// Usage prints the usage instructions of the flag set.
Usage func()
// contains filtered or unexported fields
}
FlagSet is a collection of unique flags.
func NewFlagSet ¶
func NewFlagSet(name, description string, errorHandling ErrorHandling) *FlagSet
NewFlagSet creates a new flag set with the given name, description and error handling policy.
func (*FlagSet) Bool ¶
Bool adds a new bool flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) BoolVar ¶
BoolVar adds a new bool flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) Description ¶
Description returns the given description to this flag set.
func (*FlagSet) Duration ¶
func (fs *FlagSet) Duration( name string, defaultValue time.Duration, usage string, extractors ...Extractor, ) *time.Duration
Duration adds a new time.Duration flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) DurationList ¶
func (fs *FlagSet) DurationList( name string, defaultValue []time.Duration, usage string, extractors ...Extractor, ) *[]time.Duration
DurationList adds a new []time.Duration flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) DurationListVar ¶
func (fs *FlagSet) DurationListVar( v *[]time.Duration, name string, defaultValue []time.Duration, usage string, extractors ...Extractor, )
DurationListVar adds a new []time.Duration flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) DurationVar ¶
func (fs *FlagSet) DurationVar( v *time.Duration, name string, defaultValue time.Duration, usage string, extractors ...Extractor, )
DurationVar adds a new time.Duration flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) Float ¶
func (fs *FlagSet) Float( name string, defaultValue float64, usage string, extractors ...Extractor, ) *float64
Float adds a new float64 flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) FloatList ¶
func (fs *FlagSet) FloatList( name string, defaultValue []float64, usage string, extractors ...Extractor, ) *[]float64
FloatList adds a new []float64 flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) FloatListVar ¶
func (fs *FlagSet) FloatListVar( v *[]float64, name string, defaultValue []float64, usage string, extractors ...Extractor, )
FloatListVar adds a new []float64 flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) FloatVar ¶
func (fs *FlagSet) FloatVar( v *float64, name string, defaultValue float64, usage string, extractors ...Extractor, )
FloatVar adds a new float64 flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) Init ¶
func (fs *FlagSet) Init(name, description string, errorHandling ErrorHandling)
Init initializes the flag set with the given name, description and error handling policy.
func (*FlagSet) Int ¶
func (fs *FlagSet) Int( name string, defaultValue int, usage string, extractors ...Extractor, ) *int
Int adds a new int flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) Int64 ¶
func (fs *FlagSet) Int64( name string, defaultValue int64, usage string, extractors ...Extractor, ) *int64
Int64 adds a new int64 flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) Int64List ¶
func (fs *FlagSet) Int64List( name string, defaultValue []int64, usage string, extractors ...Extractor, ) *[]int64
Int64List adds a new []int64 flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) Int64ListVar ¶
func (fs *FlagSet) Int64ListVar( v *[]int64, name string, defaultValue []int64, usage string, extractors ...Extractor, )
Int64ListVar adds a new []int64 flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) Int64Var ¶
func (fs *FlagSet) Int64Var( v *int64, name string, defaultValue int64, usage string, extractors ...Extractor, )
Int64Var adds a new int64 flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) IntList ¶
func (fs *FlagSet) IntList( name string, defaultValue []int, usage string, extractors ...Extractor, ) *[]int
IntList adds a new []int flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) IntListVar ¶
func (fs *FlagSet) IntListVar( v *[]int, name string, defaultValue []int, usage string, extractors ...Extractor, )
IntListVar adds a new []int flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) IntVar ¶
func (fs *FlagSet) IntVar( v *int, name string, defaultValue int, usage string, extractors ...Extractor, )
IntVar adds a new int flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) Lookup ¶
Lookup returns the defined flag with the given name. It will return nil if it's not found.
func (*FlagSet) Output ¶
Output returns the destination writer for the usage and error messages. If no output was set, the default is os.Stderr.
func (*FlagSet) PrintDefaults ¶
func (fs *FlagSet) PrintDefaults()
PrintDefaults prints all flags with their description and default value.
func (*FlagSet) String ¶
String adds a new string flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) StringList ¶
func (fs *FlagSet) StringList( name string, defaultValue []string, usage string, extractors ...Extractor, ) *[]string
StringList adds a new []string flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) StringListVar ¶
func (fs *FlagSet) StringListVar( v *[]string, name string, defaultValue []string, usage string, extractors ...Extractor, )
StringListVar adds a new []string flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) StringVar ¶
func (fs *FlagSet) StringVar( v *string, name string, defaultValue string, usage string, extractors ...Extractor, )
StringVar adds a new string flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) Uint ¶
func (fs *FlagSet) Uint( name string, defaultValue uint, usage string, extractors ...Extractor, ) *uint
Uint adds a new uint flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) Uint64 ¶
func (fs *FlagSet) Uint64( name string, defaultValue uint64, usage string, extractors ...Extractor, ) *uint64
Uint64 adds a new uint64 flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) Uint64List ¶
func (fs *FlagSet) Uint64List( name string, defaultValue []uint64, usage string, extractors ...Extractor, ) *[]uint64
Uint64List adds a new []uint64 flag and returns a pointer to the value that will be filled once the flag set is parsed.
func (*FlagSet) Uint64ListVar ¶
func (fs *FlagSet) Uint64ListVar( v *[]uint64, name string, defaultValue []uint64, usage string, extractors ...Extractor, )
Uint64ListVar adds a new []uint64 flag. When the flag set is parsed it will fill the given pointer.
func (*FlagSet) Uint64Var ¶
func (fs *FlagSet) Uint64Var( v *uint64, name string, defaultValue uint64, usage string, extractors ...Extractor, )
Uint64Var adds a new uint64 flag. When the flag set is parsedit will fill the given pointer.
func (*FlagSet) UintList ¶
func (fs *FlagSet) UintList( name string, defaultValue []uint, usage string, extractors ...Extractor, ) *[]uint
UintList adds a new []uint flag and returns a pointer to the value that will be filled once the flag set is parsed.
type ParseFunc ¶
ParseFunc is a function that will parse the given data and put the result into the given destination.
type Source ¶
type Source interface {
// Open allows the Source to perform some initialization before parsing.
Open() error
// Get will try to get the given key from the source and fill the Value.
Get(key string, dst Value) (bool, error)
// Close is called after parsing to release all used resources by the
// source. Close should be tolerant to multiple calls, even if it has
// not been opened.
Close() error
}
Source provides values for the flags.
func EnvPrefix ¶
EnvPrefix will provide as values the environment variables that match the given prefix.
func NewFileSource ¶
NewFileSource returns a Source that will read the given file and use the given parser to extract the contents of it.