Posts

Showing posts with the label cli

[Level 3] Use cmd module to create python cli program.

How to use cmd module to create python cli program? Please refer to the following sample: $ cat ./cli.py #!/usr/bin/python import os, sys from menu.CLI_main import CLI_main ###################################### main if __name__ == '__main__':     cli=main("user","host")     cli.cmdloop() $ $ cat ./main.py  import cmd class main(cmd.Cmd):     def __init__(self, user, host):         cmd.Cmd.__init__(self)         self.user = user         self.host = host         self.prompt = "%s@%s:%s> " % (user, host, "main")     def do_system(self, args):         from system import system         sub_cmd = system(self.user, host)         sub_cmd.cmdloop()     def help...