[[!tag cliapp python programming]]

Whenever I develop a little command line tool, I end up writing some boilerplate code. For example:

import optparse

p = optparse.OptionParser()
p.add_option('--output', metavar='FILE', help='write output to FILE')
...

Option parsing is one of those things that is easy to do, but doing it over and over again gets tedious.

There's a bunch of things that pretty much all of my command line tools end up needing to do, even if they're throwaways:

  • parse the command line, including option
  • set up logging
  • iterate over command line arguments
  • open input files
  • iterate over input lines

A while ago I decided that it was silly of me to write that code repeatedly, or to copy-paste things from project to project. Instead, I decided, I would write a framework that does things for me, and requires minimal setup code from me.

cliapp is the result. Its API seems to now be stabilizing, so I thought I'd mention it publically, in case others might find it useful, too. So far, I've found it quite liberating to be able to crank out small scripts more easily than before. My threshold for switching from shell to Python is now quite a bit lower.

I have one example online, to give flavor. The README has some explanation of what's going on.

There's a Debian package on my code hosting site; see link from cliapp's home page.

I'd welcome any feedback.