docopt icon indicating copy to clipboard operation
docopt copied to clipboard

Better error messages on duplicate args?

Open mrjbq7 opened this issue 12 years ago • 4 comments

If you specify an argument twice, then it just prints the usage, which is super not helpful for knowing why it didn't work.

Seems to me, either print an error message that indicates "duplicate option foo detected", or let the second instance override the first. I prefer the first behavior, or the second if it was opt-in, not default...

Thoughts?

mrjbq7 avatar May 21 '13 21:05 mrjbq7

I agree, better error messages a necessary in many cases.

keleshev avatar May 22 '13 07:05 keleshev

Like mutually exclusive options, that are both given.

CharString avatar Aug 21 '13 09:08 CharString

I spent the evening working myself into docopt. I considered applying it instead of argparse, for a new thing I am working on. I find it awesome, in principle, but I think the awesomeness becomes seriously damaged, when something as simple as this does not provide a useful error message:

 $ python docopttest.py --move rules
Usage:
    timegaps [--delete | --move=DIR]  FILTER_RULES

The argument to --move is missing, or the required positional argument FILTER_RULES is missing, but docopt does not say anything about any of these problems. This is stripped down, my interface is more complicated. Reporting a specific error to the user is of imminent importance for a complex commandline interface. Just printing the usage message without breaking down the error for the user is a huge disadvantage over argparse.

Actually, it was quite difficult for me to create a non-trivial scenario where docopt prints a specific error at all. Here is one:

22:00:58 $ python docopttest.py --move
--move requires argument
Usage:
    timegaps [--delete | --move=DIR]  FILTER_RULES

That's fine, but for anything slightly more complex, I can't get docopt give a precise error.

For something like this, again, no further breakdown:

$ python docopttest.py --delete --move rules
Usage:
    timegaps [--delete | --move=DIR]  FILTER_RULES

I am erroneously using --delete and --move at the same time, and missing the argument to --move, or the required pos arg FILTER_RULES. It does not matter to me which of the errors is printed, but at least one of them should be precisely reported to the user.

I will use argparse for now, and the reason is the automatic error reporting. Is it easy for docopt to precisely detect such errors and print corresponding messages? Is this something considered for future development?

Thanks for the great idea and efforts behind docopt!

jgehrcke avatar Feb 06 '14 21:02 jgehrcke

Lack of useful error reporting in most cases is a serious problem. It's the only thing keeping me from using docopt for everything I do.

Unfortunately, that means I can't really use it for anything I do :/

winni2k avatar Mar 25 '18 18:03 winni2k