Skip to content

cristalhq/flagx

Repository files navigation

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.