Go flag utils.
- Simple API.
- Dependency-free.
- Clean and tested code.
- Fully compatible with
flag
package.
See GUIDE.md for more details.
Go version 1.17+
go get github.com/cristalhq/flagx
args := []string{"-t", "20s"} // or os.Args[1:]
var d time.Duration
fset := flagx.NewFlagSet("testing", os.Stderr)
fset.Duration(&d, "timeout", "t", 10*time.Second, "just a timeout")
err := fset.Parse(args)
if err != nil {
panic(err)
}
fmt.Println(d)
// Output: 20s
Also see examples: examples_test.go.
See these docs.