Documentation
¶
Index ¶
- func Bind(fs *flag.FlagSet, v interface{}) error
- func BindEnvExpanded(fs *flag.FlagSet, v interface{}) error
- func BindEnvExpandedWithPrefix(fs *flag.FlagSet, v interface{}, prefix string) error
- func BindWithPrefix(fs *flag.FlagSet, v interface{}, prefix string) error
- func Parse(v interface{}) error
- type InvalidBindError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bind ¶
Bind defines flags based on the struct field tags and binds flags to the corresponding fields. If v is nil or not a pointer of struct, Bind returns InvalidBindError.
Bind uses 'flago' field tag to specify the name and usage of the flag. If a field does not have a 'flago' field tag, it will be ignored.
If a field is struct type, Bind will parse it recursively, and its field tag will be used as a prefix of the names of the flags defined by itself.
Supported Field Types:
- string
- bool
- int
- int64
- uint
- uint64
- float64
- time.Duration
- flag.Value
Examples:
type Example struct {
// Name defines a 'name' flag, and its usage message is not set (empty string).
Name string `flago:"name"`
// Age defines a 'age' flag, and its usage message is 'the age of gopher'.
// The name and usage specified in the field tag are separated by comma.
// flag.IntVar()
Age int `flago:"age,the age of gopher"`
}
func BindEnvExpanded ¶ added in v0.4.0
BindEnvExpanded defines exv-expanded flags based on the struct field tags and binds flags to the corresponding fields.
func BindEnvExpandedWithPrefix ¶ added in v0.4.0
BindEnvExpandedWithPrefix defines env-expanded flags with prefix.
func BindWithPrefix ¶ added in v0.3.0
BindWithPrefix defines flags with prefix. See the comments of Bind for more details.
Types ¶
type InvalidBindError ¶
An InvalidBindError describes an invalid argument passed to Bind.
func (*InvalidBindError) Error ¶
func (e *InvalidBindError) Error() string