[Python-Dev] Re: RFC: Option Parsing Libraries
David Boddie
david@boddie.net
Tue, 12 Feb 2002 15:08:20 +0000
Paul Prescod wrote:
> Greg Ward has proposed to add his Optik module to the Python library.
>
> * http://mail.python.org/pipermail/python-dev/2002-February/019934.html
>
> Optik is a parser for command line options with the features described
> here:
>
> * http://mail.python.org/pipermail/python-dev/2002-February/019937.html
>
> If you have a competitive library, or suggestions for changes to Optik,
> please forward your comments to python-dev mailing list
> (python-dev@python.org). If a long-running conversation ensues, you may
> need to join the list to participate. Discussions in comp.lang.python
> will not be considered unless you at least forward a reference to
> python-dev. If you propose a competitor to Optik, please describe how it
> compares to the feature list described above.
I have been working on a library which I hope begins to unify the
presentation of arguments to the programmer with the syntax that is
presented to the user.
In the form of the list in the first reference above:
cmdsyntax.py (Feb 2002)
Author: David Boddie <david@boddie.net>
URL: http://www-solar.mcs.st-and.ac.uk/~davidb/Software/Python/cmdsyntax/
* An attempt at OO design, with limited functionality allowing you to:
1. Set up a syntax object using a syntax definition.
2. Supply arguments from sys.argv or a string and retrieve either:
2a. A dictionary containing values corresponding to the required
arguments.
2b. A list of possible matches with the definition.
* Arguments passed must conform to a familiar looking syntax definition.
For example, the string "infile [-o outfile]" indicates that one argument
is necessary and that another may be specified using the -o switch.
* Short and long options are allowed.
The short options cannot accept arguments as in the example "-ffoo",
but lists of options such as "-avx" are supported and accept
combinations of these options in any order.
Long options support both the "--no-value" and "--name=value"
variants.
* Command arguments may be specified, which must be matched
exactly by user input, as in the case
"add"|"remove" value
which requires that either the command "add" or "remove" be given
with a following argument.
* Arguments/options may be grouped using brackets.
* No type information is specified, so arguments are not typed before
being presented to the programmer.
* Excessive method used to match arguments with the syntax definition:
all possible definitions are generated then arguments are matched
against each one.
* No ability to catch remaining unspecified arguments.
* No license.
* Needs more testing.
I'm not proposing this as a competitor to Optik, but I'm happy to donate any
ideas and code to the effort.
David
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________