Documentation ¶
Overview ¶
Package flagutil facilitates creation of rich flag types.
Example ¶
var when time.Time var re *regexp.Regexp flags := pflag.NewFlagSet("flags", pflag.PanicOnError) flags.Var(Time(&when), "when", "sets the time when it happens") flags.Var(Regexp(&re), "re", "pattern to tell if it's a match") if err := flags.Parse([]string{ "--when", "13:02", "--re", "a match$", }); err != nil { panic(err) } fmt.Println("it happens at", when.Format(time.Kitchen), re.MatchString("it's a match"))
Output: it happens at 1:02PM true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var TimeFormats = []string{ log.MessageTimeFormat, log.FileTimeFormat, time.RFC3339Nano, time.RFC3339, time.Kitchen, "15:04:00.999999Z", "15:04:00.999999", "15:04Z", "15:04", }
TimeFormats are the time formats which a time flag accepts for parsing time as described in time.Parse.
Functions ¶
func Regexp ¶
Regexp returns a value which can be used with pflag.Var to create flags for regexp variables. The flag attempts to compile its input to a regular expression and assigns the result to *r. If the flag is empty, r is set to nil.
func Time ¶
Time returns a value which can be used with pflag.Var to create flags for time variables. The flag attempts to parse its in a variety of formats. The first is as a duration using time.ParseDuration and subtracting the result from Now() and then by using the values in Formats for parsing using time.Parse. An empty flag sets t to the zero value.
Types ¶
This section is empty.