Powerful Command line parsers

P

PyPK

Is there a Command line parser in python that can:
1. resolve conflicts
2. specify something like requires
3. and smart

for ex:
python test.py --a --b --c --d

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.
 
J

John Machin

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.
 
L

Lawrence D'Oliveiro

John Machin said:
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")

Prolog-style predicates. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top