Automatically registering "commands" for a command line program in python
Posted
by
seandavi
on Stack Overflow
See other posts from Stack Overflow
or by seandavi
Published on 2011-01-09T22:48:39Z
Indexed on
2011/01/09
22:54 UTC
Read the original article
Hit count: 173
python
|command-line-tool
I would like to develop a command-line program that can process and give "help" for subcommands. To be concrete, say I have a single script called "cgent" and I would like to have subcommands "abc", "def", and "xyz" execute and accept the rest of the sys.args for processing by optparse.
cgent abc [options] cgent help abc ....
All of this is straightforward if I hard-code the subcommand names. However, I would like to be able to continue to add subcommands by adding a class or module (?). This is similar to the idea that is used by web frameworks for adding controllers, for example. I have tried digging through pylons to see if I can recreate what is done there, but I have not unravelled the logic. Any suggestions on how to do this?
Thanks, Sean
© Stack Overflow or respective owner