flagutil

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

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

View Source
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

func Regexp(r **regexp.Regexp) pflag.Value

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

func Time(t *time.Time) pflag.Value

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL