|
|
|||||||||||||||||||||||||
|
Comparing Option-Parsing LibrariesNOTE: this page is present for historical purposes only. The getopt-sig is retired, and Optik was added to the Python standard library (as optparse) in Python 2.3. (It was checked in to Python's CVS tree in November 2002, and first released in July 2003.) Since I proposed Optik for the Python standard library, a number of other option-parsing libraries have come to light. I'm trying to evaluate them by implementing the same real-world command-line interface with several different libraries. Currently, implementations exist for:
User interfaceThe interface I have chosen to implement is that of my ripoff CD-ripping script. The main features of this interface are:
To keep things concrete, here is Ripoff's help text (as generated by Optik). One weakness of Ripoff's command-line interface is that several flag options don't have a negative counterpart: eg. there is a --keep-tmp option, but no --no-keep-tmp. That sort of thing really is necessary in the real world, where a program's default (no-keep-tmp in this case) might be overridden by a config file, and then overridden again on the command-line. This weakness is currently reflected in all three of my test re-implementations. Internal interfacesInternally, Ripoff works by passing around a single object that
contains all the values from the command-line. E.g., the user-selected
verbosity level is in I have preserved this in all of my test re-implementations. This works to Optik's benefit (since it already puts option values in a dedicated object); doesn't have much affect on the iterator version (it just means a bit more typing); and it makes argtools look bad, since I have to explicitly copy all of my option values from the parser object to my dedicated option values object. And now, ladies and gentlemen...Enough delay, on with the show! First, some simple statistics about the three re-implementations:
But as Mark Twain said: there are lies, damned lies, and statistics. So let's see some code.
If you actually want to run any of these without modifying them,
you'll need to get the Ripoff source code from
its CVS
repository. This is because I wanted 1) a realistic --version
option (which uses |