Hi, guys. I have seen some CLI questions here, but I still want to ask this question for more detailed answers.
I have already developed class1.py, class2.py, etc. with functions implemented inside each class. e.g. Operator.py has add, minus,time, devide functions. how can I build a command line interface for these classes?
also for this CLI, is it a infinite loop inside the main() for interaction?
And how can the CLI give some feedback such as, suggesting the user for the next operation or to input right command or type --help and check all the available commands. like the Bash shells.
also it seems there is optparse module from python. is there some good, complete, or high quality samples showing how a CLI is built? I would like to take this chance to learn how to write a CLI program.
what i want is: I have already developed several classes, and also a GUI to call the methods from these classes. Now i want to have a CLI, like the GUI, to use these classes. e.g. I have classes like CDContainer (with method like addCD, removeCD, etc), CD (with method like play, stop, pause), and I have a GUI that could be interacted. Now I want to have a CLI, which under the bash, I could run this CLI and call createCDContainer, addCD, removeCD commands.
If I use cmd,
class CDContainerCLI(cmd.Cmd):
def do_CDContainer(self, line):
print "create CD container"
def do_addcd(self, line):
print "add cd into the container"
how do I add some options here? e.g., I want to addcd --track 3 --cdname thriller I think "--track 3 --cdname thriller" they are the 4 arguments for the addcd function. how to implement that?