Add collected and left to DocoptExit for more exception info
Merge this PR! Make docopt more flexible and powerful by allowing to use it as a parser for known patterns and write your own exception handling for the stuff that didn't parse! :)
Let's say you have this use case (which I do)
my-program --known-option [ANYTHING ...]
...then currently, it's hard to make docopt actually understand that I really want ANYTHING to be handled after the known options. I'll just use whatever is parsed after to give to another program.
So this would be my use case:
try:
arguments = docopt(__doc__, version=str(VERSION), options_first=False)
except DocoptExit as e:
if not e.collected:
raise
arguments = e.collected
arguments['ANYTHING'] = e.left
I found that in order to work around docopts shortcoming, I had to copy all of docopt() and edit the function body, which was kind of ugly.
@keleshev any chance to have this merged?
Rebased to master! @mboersma would this be interesting?
Merged at https://github.com/bazaar-projects/docopt/commit/cda7de0d560aac542960cd4360e9afdda2dfa84a - thanks!