[Freeipa-devel] Proposal: Use argparse for option parsing
Petr Viktorin
pviktori at redhat.com
Fri Oct 12 15:04:57 UTC 2012
Hello,
I read through https://fedorahosted.org/freeipa/ticket/3060 and noticed
that the requirements are similar to what an existing library offers.
The optparse module we currently use for CLI option parsing is
deprecated[1]. The replacement is called argparse, which is part of the
Python 2.7 standard library. Out of the box, it provides several
features we either lack or had to handle manually, namely:
* supporting sub-commands [2]
* producing more informative usage messages [2]
* handling both optional and positional arguments [3]
* as well as including a number of other more minor improvements on the
optparse API. [3]
The package has also been backported to Python 2.6, the only catch there
is that it's not in the standard library.
Not much of our code calls optparse directly, so switching shouldn't be
a major effort (within the scope of reorganizing the help system). In
exchange we get better CLI help messages, forward compatibility, and
reuse of proven code instead of our own solutions.
[1] http://docs.python.org/library/optparse.html
[2] http://code.google.com/p/argparse/
[3] yum info python-argparse (EPEL-6)
--
Petr³
More information about the Freeipa-devel
mailing list