blerp (with docopt)

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 scripts1.

So when I saw xkcd #1692 I turned to Python and docopt to see if it Just Works™2. It almost does, I had to change just 3 things:

  • change SYNOPSIS with 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 OPTIONS ]

I also added two customary commands for your convenience: blerp xkcd and blerp help.

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 to learn more.


Share on Facebook4Tweet about this on TwitterShare on Reddit0Buffer this pageFlattr the author

  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.