Documentation ¶
Index ¶
- Variables
- func Bool(name string, def bool, usage string) *bool
- func BoolVar(p *bool, name string, def bool, usage string)
- func Int(name string, def int, usage string) *int
- func IntVar(p *int, name string, def int, usage string)
- func Parse()
- func String(name string, def string, usage string) *string
- func StringVar(p *string, name string, def string, usage string)
- type ErrorHandling
- type Value
- type VariableSet
- func (set *VariableSet) Bool(name string, def bool, usage string) *bool
- func (set *VariableSet) BoolVar(p *bool, name string, def bool, usage string)
- func (set *VariableSet) Int(name string, def int, usage string) *int
- func (set *VariableSet) IntVar(p *int, name string, def int, usage string)
- func (set *VariableSet) Parse(environments []string) error
- func (set *VariableSet) String(name string, def string, usage string) *string
- func (set *VariableSet) StringVar(p *string, name string, def string, usage string)
Constants ¶
This section is empty.
Variables ¶
var Default = NewVariableSet("", ExitOnError)
Default is the default set of environment variable set, parsed from os.Environment().
var Usage = func() string { return Default.Usage() }
Usage returns Default.Usage().
Functions ¶
func Bool ¶
Bool defines a bool value with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the environment variable.
func BoolVar ¶
BoolVar defines a bool environment variable with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the environment variable.
func Int ¶
Int defines a int value with specified name, default value, and usage string. The return value is the address of a int variable that stores the value of the environment variable.
func IntVar ¶
IntVar defines a int environment variable with specified name, default value, and usage string. The argument p points to a int variable in which to store the value of the environment variable.
func Parse ¶
func Parse()
Parse parses the environment variables from os.Environ(). Must be called after all variables are defined and before variable are accessed by the program.
Types ¶
type ErrorHandling ¶
type ErrorHandling int
ErrorHandling defines how VariableSet.Parse behaves if the parse fails.
const ( ContinueOnError ErrorHandling = iota // Return a descriptive error. ExitOnError // Call os.Exit(2). PanicOnError // Call panic with a descriptive error. )
These constants cause VariableSet.Parse to behave as described if the parse fails.
type VariableSet ¶
type VariableSet struct { Usage func() string // contains filtered or unexported fields }
A VariableSet represents a set of defined environment variable. The zero value of a FlagSet has no name and has ContinueOnError error handling.
Flag names must be unique within a FlagSet. An attempt to define a flag whose name is already in use will cause a panic.
func NewVariableSet ¶
func NewVariableSet(name string, handling ErrorHandling) *VariableSet
NewVariableSet returns a new, empty variable set with the specified name and error handling property. If the name is not empty, it will be printed in the default usage message and in error messages.
func (*VariableSet) Bool ¶
func (set *VariableSet) Bool(name string, def bool, usage string) *bool
Bool defines a bool value with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the environment variable.
func (*VariableSet) BoolVar ¶
func (set *VariableSet) BoolVar(p *bool, name string, def bool, usage string)
BoolVar defines a bool environment variable with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the environment variable.
func (*VariableSet) Int ¶
func (set *VariableSet) Int(name string, def int, usage string) *int
Int defines a int value with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the environment variable.
func (*VariableSet) IntVar ¶
func (set *VariableSet) IntVar(p *int, name string, def int, usage string)
IntVar defines a int environment variable with specified name, default value, and usage string. The argument p points to a int variable in which to store the value of the environment variable.
func (*VariableSet) Parse ¶
func (set *VariableSet) Parse(environments []string) error
Parse parses the environment variables from argument. Must be called after all variables are defined and before variable are accessed by the program.
func (*VariableSet) String ¶
func (set *VariableSet) String(name string, def string, usage string) *string
String defines a string value with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the environment variable.
func (*VariableSet) StringVar ¶
func (set *VariableSet) StringVar(p *string, name string, def string, usage string)
StringVar defines a string environment variable with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the environment variable.