You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd love it if there was support for multiple instance options that count their repetition instead of accepting multiple values. This is commonly used for verbosity where a setup, something along the lines of
would allow for --verbose blah -v on the command line would set args.verbose == 2, -vvv would set args.verbose == 3, etc. And not specifying any verbosity options would set args.verbose == 0.
The text was updated successfully, but these errors were encountered:
Hey @runeimp - thanks for the suggestion. This seems quite reasonable, but it also feels like it might only be used for the common "verbose" flag. I can't really think of another realistic use-case. I wonder if it would be better just to do it manually with something like
func main() {
var verbose int
for i, arg := range os.Args {
if strings.TrimRight(arg, "v") == "-" {
verbose = len(arg) - 1
os.Args = append(os.Args[:i], os.Args[i+1:]...)
break
}
}
var args struct {
...
}
arg.MustParse(&args)
...
}
This seems like a reasonably small amount of code for the special case of "-v", whereas implementing the general version inside go-arg and covering all the corner cases feels like it would add quite a bit of complexity.
I totally understand. I've seen it used in other places but verbosity is definitely the major use case. Thanks for the suggestion on how to work around it.
I'd love it if there was support for multiple instance options that count their repetition instead of accepting multiple values. This is commonly used for verbosity where a setup, something along the lines of
would allow for
--verbose blah -v
on the command line would setargs.verbose == 2
,-vvv
would setargs.verbose == 3
, etc. And not specifying any verbosity options would setargs.verbose == 0
.The text was updated successfully, but these errors were encountered: