Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
flag: handles unknown arguments in an unexpected less-helpful way #15352
If the flag library encounters an unknown parameter, it discards that parameter and dumps everything else in the positional arguments bucket.
Instead, the flag library should (optionally, probably when ContinueOnError is specified) put all unknown parameters in the positional arguments bucket (returned by Args) and keep attempting to parse the following arguments. (unless encountering something that clearly indicated the beginning of positional arguments such as the naked double-dash "--")
list == "first", "second", "third"
I want to make sure I understand your concern correctly:
Let's say the command line looks like this:
The user intends for the value of unknown to be "--known" and "foo" to be a positional argument.
I agree this could be problematic. But it seems unlikely to come up regularly. Most likely, the program will break in a way apparent to the user and they can modify their command line to read
What about the other half of my proposal? It seems to me at least that flagSet.Arg() should return the first unknown argument instead of only subsequent arguments.
flag package recognizes only the following syntax for flags:
If you change
+1 -- I was recently writing a small go program that invoked another program with the args that were passed (amongst doing other things). I wanted to parse 2 of the args, but leave the others unchanged. I couldn't use the flag package.
ContinueOnError really means AbortOnError. There is no "real" continue on error