Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterFlagsInStruct ¶
func RegisterFlagsInStruct(pfs *pflag.FlagSet, tag string, structWithFlags interface{}, valueDefaults map[string]interface{}, usageDefaults map[string]string) error
RegisterFlagsInStruct is the same flagvar.RegisterFlagsInStruct except that it operates on pflag.FlagSet.
Example ¶
package main import ( "fmt" "github.com/spf13/pflag" "v.io/x/lib/cmd/pflagvar" ) func main() { eg := struct { A int `flag:"int-flag,-1,intVar flag"` B string `flag:"string-flag,'some,value,with,a,comma',stringVar flag"` O int }{ O: 23, } flagSet := &pflag.FlagSet{} err := pflagvar.RegisterFlagsInStruct(flagSet, "flag", &eg, nil, nil) if err != nil { panic(err) } fmt.Println(eg.A) fmt.Println(eg.B) flagSet.Parse([]string{"--int-flag=42"}) fmt.Println(eg.A) fmt.Println(eg.B) }
Output: -1 some,value,with,a,comma 42 some,value,with,a,comma
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.