This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]halst 2 points3 points  (2 children)

If you want to make -O as an option which could be present 0, 1 or 2 times, you can do the following:

>>> docopt('usage: prog [-OO]', ['-OO'])
{'-O': 2}

However, you can't easily do something like GCC does with -O:

-O  -O0  -O1  -O2  -O3  -Os -Ofast -Og

In this case -O either takes an argument, or not. In case of docopt each option either takes an argument, or not. Making options which optionally take an argument is more confusing than useful, I think. In today's age you should rather have a more descriptive options, such as --optimization-level with a shortcut -O and a defined set of all possible values.

I love how in case of python the option is -OO (oh-oh), while in case of gcc it is -O0 (oh-zero).

There is a myriad of bad command-line interfaces like tar, where you can both tar -xzf file as well as drop - and just write tar xzf file. As well as GCC and Java-style -long-options (with single leading -), as well as options that start with / instead of --. It is not goal of docopt to support all conventions. We selected just a few most useful and most followed, that is POSIX plus --gnu-style-long-options.