Add optional argument with empty default value
First of all: this library looks amazing! Great work!
Currently, there is no way to register an optional argument, unless you add an argument with a default value that is not an empty string.
So for example:
// $ reactor create <name> [version]
commando.
Register("create").
SetShortDescription("creates a component").
AddArgument("name", "name of the component to create", ""). // required
AddArgument("version", "version of the component", "1.0.0").
Version is optional here because it has a default value that is not an empty string.
For my use case, I want to add an optional value that itself is an empty string by default.
That doesn't work because of this rule:
IsRequired: defaultValue == "" && !clpArg.IsVariadic, // variadic arguments are always optional
I would like to have something like this:
// $ reactor create <name> [version]
commando.
Register("create").
SetShortDescription("creates a component").
AddArgument("name", "name of the component to create", ""). // required
AddOptionalArgument("version", "optional version to create", "").
Any idea how to solve this?
I think it can also be solved by using the same trick as AddFlag. There, it uses defaultValue interface{} which allows to pass in nil. Then nil can be for something that has no default value, and a string value will be the default value.
Hmm, turns out that it's also impossible to add a string flag with an empty default value.
AddFlag("default", "desc", commando.String, nil).
# Error: value of the --default flag can not be empty.
AddFlag("default", "desc", commando.String, "").
# Error: value of the --default flag can not be empty.
I think this needs some more thought :)
@thatisuday Any idea how to solve this or improve this?
Same issue, any solutions for this? It's bug???