Hierarchical commnd line parsing / help texts

Gelonida N gelonida at gmail.com
Mon Sep 26 04:55:42 EDT 2011


Hi,

So far I used optparse.OptionParser for parsing command line arguments
for my python scripts. So far I was happy, with a one level approach,
where I get only one help text

Now I'd like to create a slightly different python script and wondered
which approach / module might be best for implementing the parsing and
generation of help texts.

Please look at my example (let's emulate a shell in python)

$ ./sh.py
or
$ ./sh.py -h
Should create the top level help text and list possible commands
.e.g.
ls
rm
cat
and list some commands with potential sub commands
.e.g.
net
db


then if I typed ./sh.py <command> -h
I'd like to get the helptext for the specified command.

For some more complex commands I'd even like to be able to type


/sh.py <command> <subcommand> -h


Ideally, I would like to be able to parse generic options before
commands / sub commands and less generic options after the commands


./sh.py -v ls -a


Thanks in advance for suggestions






More information about the Python-list mailing list