A few types you could use with Go's flag.Var
Find a file
Yuxuan 'fishy' Wang 30b1b69959 Update to go 1.26
And modernize the codebase with go fix.
2026-08-21 19:21:15 -07: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 Update to go 1.26 2026-08-21 19:21:15 -07:00
LICENSE Initial commit 2019-01-19 17:45:06 -08:00
oneof.go Update to go 1.26 2026-08-21 19:21:15 -07:00
oneof_test.go Change to vanity import url 2020-12-26 17:30:04 -08:00
README.md Update to go 1.26 2026-08-21 19:21:15 -07:00
rgb.go Update to go 1.26 2026-08-21 19:21:15 -07:00
rgb_test.go Update to go 1.26 2026-08-21 19:21:15 -07:00
rgba.go Update to go 1.26 2026-08-21 19:21:15 -07:00
rgba_test.go Update to go 1.26 2026-08-21 19:21:15 -07: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
color := new(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.