Open insasho opened 9 years ago
Thanks for the feedback.
Good proposal, adding it to the to do list.
Not as neat as the builtin type proposed here, but I implemented something similar using the new(ish) custom type feature https://godoc.org/github.com/gwatts/flagvals#OneOfString
eg.
netMode := flagvals.NewOneOfString("bridge", "none", "container", "host)
netMode.Value = "bridge" // set a default
cmd.Var(cli.VarOpt{
Name: "net",
Desc: "Set the Network mode for the container. Either bridge, none, container or host",
Value: netMode,
})
This library is off to a great start! Support for enumerations is a common feature of flag parsing libraries and it would be great if mow.cli could support this too.
Proposed design:
Per-option help text could be set via the struct variants of the Enum methods.
My specific use case is that I need to add a flag that will support many different values over time but that only currently supports two. For example, the
--format
flag supports onlyprintable
andbinary
today but it might later needbase64
. I could use multiple boolean flags but this would require me to implement my own default-value and validation logic (undesirable).Another use case is the
--net
flag fordocker run
:Thanks.