[issue14191] argparse: nargs='*' doesn't get out-of-order positional parameters
report at bugs.python.org
Sat Mar 10 01:04:12 CET 2012
Glenn Linderman <v+python at g.nevcal.com> added the comment:
Sad. That means all the documentation of workarounds needs to be written, even figured out in the first place. Steven's code, while being a nice implementation when proper arguments are provided, produces inappropriate errors, because only the positional, or only the optional, parameters are printed when errors occur.
So it would probably take a third parser, with all the parameters defined, to exist, to allow easiest generation of the usage message, but I'm not quite sure how to catch the error printing, and redirect it to the third parser.
So, I tried the classes in t17.py; they are not complete; CompatibleArgumentParser should pass through all the other APIs, and I'm not sure if all the extension semantics can be appropriately passed through when there are three classes and two objects involved. But this is sort of a proof-of-concept wrapper for achieving intermixed optional and positional arguments, and still get proper error messages.
Added file: http://bugs.python.org/file24771/t18.py
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list