Python Forum

Full Version: a command tree
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i am wanting to implement a rather large command tree. this is on command as far as the system shell knows, it will be given a sequence of arguments. for each subcommand, more arguments designate deeper subcommands until some code for some subcommand does special things with particular arguments. for example material metal silver clean polish help might be on branch of a command tree. i am wondering if there is a good pattern to implement this on, such as each branch down the tree importing a specific module and calling some specific function. anyone have any example code patterns or ideas?
Your 'command tree' sounds surprisingly like a 'menu'
it could be like a menu, but i will be doing this as a command. there will be a leaf subcommand "help" at every point in the tree.
You could write your own DSL for the command line and create a specific parser.
(Feb-16-2018, 11:17 AM)Gribouillis Wrote: [ -> ]You could write your own DSL for the command line and create a specific parser.
how would i organize all the specific subcommands? at a minimum i want each subcommant be a distinct function. should i organize this as a bunch of imported modules for each node or for each branch?