title: How to make a command line interface or interpreter in Python
body: <p>I have already developed class1.py,  class2.py, etc. with functions implemented inside each class. e.g. Operator.py has add, minus, time, divide functions. How can I build a command line interface for these classes?</p>
  <p>Also for this CLI, is it an infinite loop inside the <code>main()</code> for interaction?</p>
  <p>And how can the CLI give some feedback such as, suggesting the user for the next operation or to input right command or type <code>--help</code> and check all the available commands, like the Bash shells?</p>
  <p>Also it seems there is the <code>optparse</code> module from Python. Are 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.</p>
  <p>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.</p>
  <p>If I use <code>cmd</code>,</p>
  <pre><code>class CDContainerCLI(cmd.Cmd):
              
      def do_CDContainer(self, line):
          print &quot;create CD container&quot;
  
      def do_addcd(self, line):
          print &quot;add cd into the container&quot;
  </code></pre>
  <p>how do I add some options here? e.g., I want to <code>addcd --track 3 --cdname thriller</code>.</p>
  <p>I think <code>--track 3 --cdname thriller</code> they are the 4 arguments for the <code>addcd</code> function. How to implement that?</p>