Created
October 17, 2014 14:57
-
-
Save damnit/d34b1f339f2f077d0d20 to your computer and use it in GitHub Desktop.
python cmd framework usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ foo cli - use this with python 3.x """ | |
| import cmd | |
| class FooShell(cmd.Cmd): | |
| """ mite shell command class. """ | |
| def __init__(self): | |
| super(FooShell, self).__init__() | |
| self.intro = 'Using foo from CLI. Type help or ? to list commands.\n' | |
| self.prompt = '[foo] ' | |
| self.completekey = 'Tab' | |
| def do_foo(self, arg): | |
| """ foo like a fooer. """ | |
| print(arg) | |
| def do_EOF(self, line): | |
| print('BYE') | |
| return True | |
| def do_quit(self, arg): | |
| self.do_EOF(arg) | |
| return True | |
| if __name__ == '__main__': | |
| m = FooShell() | |
| try: | |
| m.cmdloop() | |
| except KeyboardInterrupt: | |
| m.do_EOF(None) | |
| # vim: set ft=python ts=4 sw=4 expandtab : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment