A few types you could use with Go's flag.Var
- Go 100%
| .editorconfig | ||
| doc.go | ||
| go.mod | ||
| LICENSE | ||
| oneof.go | ||
| oneof_test.go | ||
| README.md | ||
| rgb.go | ||
| rgb_test.go | ||
| rgba.go | ||
| rgba_test.go | ||
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
}