Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateFlagset ¶
Example ¶
testConfig := struct { A int64 `flag:"alpha" description:"an int value"` B []string `flag:"beta" description:"some strings"` C bool `flag:"gamma" hidden:"true"` }{ B: []string{"defaultvalue"}, } args := []string{"--alpha", "10", "--beta", "b", "--beta", "b2", "--gamma"} flags := CreateFlagset(&testConfig) flags.Parse(args) fmt.Println(testConfig.A) fmt.Println(testConfig.B) fmt.Println(testConfig.C)
Output: 10 [b b2] true
func RegisterConverter ¶
func RegisterConverter(targetType interface{}, converter Converter)
Types ¶
type Converter ¶
Example ¶
testConfig := struct { A CustomConvertible `flag:"alpha" description:"an int value with custom converter"` B []CustomConvertible `flag:"beta" description:"a slice of an int value with custom converter"` }{ A: CustomConvertible(1), } RegisterConverter(CustomConvertible(0), func(val string) (interface{}, error) { ival, err := strconv.Atoi(val) if err == nil { return CustomConvertible(ival), nil } return nil, err }) args := []string{"--alpha", "10", "--beta", "5"} flags := CreateFlagset(&testConfig) flags.Parse(args) fmt.Println(testConfig.A) fmt.Println(testConfig.B)
Output: 10 [5]
type ElementFilter ¶
type ElementFilter interface {
Filter(field reflect.StructField) bool
}
type FlagsetBuilder ¶
type FlagsetBuilder struct { Filter ElementFilter NameTags []string }
func NewBuilder ¶
func NewBuilder() *FlagsetBuilder
func (*FlagsetBuilder) Build ¶
func (b *FlagsetBuilder) Build(config interface{}) *flag.FlagSet
func (*FlagsetBuilder) RecurseReflectively ¶
func (b *FlagsetBuilder) RecurseReflectively(config interface{}, callback func(name string, tag reflect.StructTag, value interface{}))
func (*FlagsetBuilder) SetFilter ¶
func (b *FlagsetBuilder) SetFilter(filter ElementFilter) *FlagsetBuilder
func (*FlagsetBuilder) SetNameTags ¶
func (b *FlagsetBuilder) SetNameTags(tags ...string) *FlagsetBuilder
type StringParsable ¶
Click to show internal directories.
Click to hide internal directories.