A few types you could use with Go's flag.Var
Find a file
2020-12-26 17:30:04 -08:00
.editorconfig Initial commit 2019-01-19 17:45:06 -08:00
doc.go Change to vanity import url 2020-12-26 17:30:04 -08:00
go.mod Change to vanity import url 2020-12-26 17:30:04 -08:00
LICENSE Initial commit 2019-01-19 17:45:06 -08:00
oneof.go Initial commit 2019-01-19 17:45:06 -08:00
oneof_test.go Change to vanity import url 2020-12-26 17:30:04 -08:00
README.md Change to vanity import url 2020-12-26 17:30:04 -08:00
rgb.go Initial commit 2019-01-19 17:45:06 -08:00
rgb_test.go Change to vanity import url 2020-12-26 17:30:04 -08:00
rgba.go Initial commit 2019-01-19 17:45:06 -08:00
rgba_test.go Change to vanity import url 2020-12-26 17:30:04 -08:00

PkgGoDev Go Report Card

Go Flag Utils

This is a Go library that provides a few types you can use with flag.Var().

Sample Code

There are detailed examples for each type on pkg.go.dev, but here's a quick example:

// Default to red
var color flagutils.RGB{
	R: 0xff,
}
flag.Var(
	&color,
	"color",
	"The color to use",
)
var featureA, featureB flagutils.OneOf
flagutils.GroupOneOf(&featureA, &featureB)
flag.Var(
	&featureA,
	"featureA",
	"Run feature A, unsets featureB",
)
flag.Var(
	&featureB,
	"featureB",
	"Run feature B, unsets featureA",
)
flag.Parse()
switch {
case featureA.Bool:
	// Run feature A
case featureB.Bool:
	// Run feature B
}

License

BSD License.