Skip to content

Instantly share code, notes, and snippets.

@damnit
Created October 17, 2014 14:57
Show Gist options
  • Select an option

  • Save damnit/d34b1f339f2f077d0d20 to your computer and use it in GitHub Desktop.

Select an option

Save damnit/d34b1f339f2f077d0d20 to your computer and use it in GitHub Desktop.
python cmd framework usage
""" 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