command line command structure representation

Bruce Edge bedge at troikanetworks.com
Thu Mar 1 10:35:26 EST 2001


I'm doing a command line interface in python.
I'm going to make extensive use of the completer and readline libraries
for line editing.
In order to intelligently complete commands at any point, I need to
represent the command heirarchy tree with all available options,
arguments, etc in python. 
Is there anything out there (besides rapid logic's CLI package) to aid
in this task?

I've derived my own class from rlcompleter which looks for a list of my
commands and intercepts the completion key (tab) if one is detected. 
Each command has syntax like this

add widget <name> [[not]opt1 xxx] [[not]opt2 yyy] [[not]flag1]
[[not]flag2]

So my command tree representation will have to mark field types as:
- base command name, eg: add, delete, modify...
- non-promptable user entered string/number ie: no completion possible
- string/number from predefined list, completer cycles through these
- string/number from dynamically constructed list, completer options
built on demand.
- optional negation prefix, ie: not or no etc.

I know it's not that difficult to just create a set of nested structures
for this, but I'm trying to make something that is easily
extensible/maintanable, perhaps a way of embedding the command structure
tree in the command implementation classes themselves, and building it
at runtime though introspection.
Or, some kind of tree editor?

Any thoughts or suggestions?


Thanks, Bruce.



More information about the Python-list mailing list