go-arg
go-arg copied to clipboard
Repeated flags not detected....
I can do something like -h -h -h and this is treated as a single -h rather than as an error. Yet -hhhh is treated as an error.
Closely related, some argument parsers allow for special "count" flags. For example, I typically like to use -vvv to specify verbosity/debug level, much like the ssh command does. It would seem to me that it would require a special kind of tag, "counted", much like the existing "positional".
Indeed this is not possible with the current API. One option would be to do it manually like this:
var args struct {
H bool `arg:"-h"`
}
arg.MustParse(&args)
var hCount int
for _, s := range os.Args() {
if s == "-h" {
hCount += 1
}
}
I admit you're basically working around go-arg at this point but at least it would interoperate with other flags that are parsed by go-arg.
Actually I was looking for the -h -h -h case to be recognized as an error by default. It's actually the "-vvvv" case that I really want to count... Hence, something like:
Level uint `arg:"counted,-v"`
This is a common feature in pflag, and often used in c/c++ option parsers, but yes, it's probably not easy to implement. Or maybe, if it is found in Args() it could be stripped out and replaced with a single -v before MustParse sees it? But the help message would be wrong if it is Level, so I guess it would have to be a dummy bool field. But that of course is also missing the point of the package if we have to steal flags and parse around it...
It's actually the "-vvvv" case that I really want to count...
I badly need that as well, as I also "like to use -vvv to specify verbosity/debug level, much like the ssh command does"
Will try to support this in upcoming v2