docopt icon indicating copy to clipboard operation
docopt copied to clipboard

Add collected and left to DocoptExit for more exception info

Open benjaoming opened this issue 10 years ago • 3 comments

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.

benjaoming avatar Jun 12 '15 15:06 benjaoming

@keleshev any chance to have this merged?

benjaoming avatar Dec 17 '15 19:12 benjaoming

Rebased to master! @mboersma would this be interesting?

benjaoming avatar May 20 '16 18:05 benjaoming

Merged at https://github.com/bazaar-projects/docopt/commit/cda7de0d560aac542960cd4360e9afdda2dfa84a - thanks!

itdaniher avatar Mar 21 '19 01:03 itdaniher