docopt is a Python module to “create beautiful command-line interfaces” (cit.) and I really like it.
I think it is an elegant solution to the problem of command line interfaces. I also use its Bash port, called
docopts, to create command-line interfaces for shell scriptsI see some of you complaining. I know that docopt is not perfect, but it is awesome enough for my taste. There are several other modules for creating command-line interfaces for Python scripts: from … Continue reading.
USAGE:(docopt expects a
Usage:line somewhere in the docstring)
- add a closed bracket in the first usage pattern matching
[ ARGS ...
- add an open bracket in the second usage pattern to match
I also added two customary commands for your convenience:
blerp xkcd and
The code is on GitHub, if you want to add some features fell free to open a PR.
I am quite amazed by the fact that this Almost Just Works™, so if you do not know docopt watch this talk and go over docopt.org to learn more.
|↑1||I see some of you complaining. I know that docopt is not perfect, but it is awesome enough for my taste. There are several other modules for creating command-line interfaces for Python scripts: from argparse – which is part of Python standard library since version 2.7 – or the much more advanced click. But still, I love the semplicity of docopt.|
|↑2||Also HT to explainxkcd, which saved me quite a lot of typing.|