Powerful Command line parsers
John Machin
sjmachin at lexicon.net
Fri Apr 21 19:29:54 EDT 2006
On 22/04/2006 4:15 AM, PyPK wrote:
> Is there a Command line parser in python that can:
> 1. resolve conflicts
> 2. specify something like requires
> 3. and smart
"... that can ... and smart" does not compute.
>
> for ex:
> python test.py --a --b --c --d
I'm used to seeing --fubar and -f; what does --f mean?
>
> Case 1:
> If 'a' is an option 'b' or 'c' cannot be specified.
>
> Case 2:
> atleast one option should be specified
>
> Case 3:
> IF 'a' and 'c' are given then 'd' has to be given
>
> or many such cases.
>
> I was wondering as this is a very common problem there if there is a
> module that could do these things .
> 'optparse' is not this smart I guess.
Modules are neither dumb nor smart. The author of optparse is IMHO
smart; it does just about what it ought to do.
To meet your specifications, the module would need to incorporate a
mini-language:
if a and (b or c): nasty("blah 1")
if not (a or b or c or d): nasty("blah 2")
if a and c and not d: nasty("blah 3")
Again IMHO, it would be an enormous waste of effort to implement such a
mini-language inside a command-line parser, when the call to the parser
can be followed by whatever conditions and actions you like, written
in Python.
More information about the Python-list
mailing list