-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeated flags not detected.... #170
Comments
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:
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... |
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 |
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".
The text was updated successfully, but these errors were encountered: