kastolars / flagx

Go flag utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flagx

build-img pkg-img reportcard-img coverage-img version-img

Go flag utils.

Features

  • Simple API.
  • Dependency-free.
  • Clean and tested code.
  • Fully compatible with flag package.

See GUIDE.md for more details.

Install

Go version 1.17+

go get github.com/cristalhq/flagx

Example

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.

Documentation

See these docs.

License

MIT License.

About

Go flag utils

License:MIT License


Languages

Language:Go 100.0%