Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a command tree
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Your 'command tree' sounds surprisingly like a 'menu'
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
You could write your own DSL for the command line and create a specific parser.
Reply
#5
(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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020