summaryrefslogtreecommitdiff
path: root/examples/migrating.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-16 11:46:31 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-16 11:46:31 -0400
commit3636ffe8af04ec0d04769599520c53838d872f7f (patch)
treed3bd036fe7ca25af2afb144580989b714c995741 /examples/migrating.py
parent9b38c8c2a5da60676b49f91f4671be2e1e8b0d0e (diff)
parenteb882b2b308bb2e09761a74007ea308b489c2d56 (diff)
downloadcmd2-git-3636ffe8af04ec0d04769599520c53838d872f7f.tar.gz
Merge branch 'master' into default_sort_key
Diffstat (limited to 'examples/migrating.py')
-rw-r--r--examples/migrating.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/migrating.py b/examples/migrating.py
new file mode 100644
index 00000000..3a25b8c8
--- /dev/null
+++ b/examples/migrating.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# coding=utf-8
+"""
+A sample application for cmd which can be used to show how to migrate to cmd2.
+"""
+import random
+
+import cmd
+
+
+class CmdLineApp(cmd.Cmd):
+ """ Example cmd application. """
+
+ MUMBLES = ['like', '...', 'um', 'er', 'hmmm', 'ahh']
+ MUMBLE_FIRST = ['so', 'like', 'well']
+ MUMBLE_LAST = ['right?']
+
+ def do_exit(self, line):
+ """Exit the application"""
+ return True
+
+ do_EOF = do_exit
+ do_quit = do_exit
+
+ def do_speak(self, line):
+ """Repeats what you tell me to."""
+ print(line, file=self.stdout)
+
+ do_say = do_speak
+
+ def do_mumble(self, line):
+ """Mumbles what you tell me to."""
+ words = line.split(' ')
+ output = []
+ if random.random() < .33:
+ output.append(random.choice(self.MUMBLE_FIRST))
+ for word in words:
+ if random.random() < .40:
+ output.append(random.choice(self.MUMBLES))
+ output.append(word)
+ if random.random() < .25:
+ output.append(random.choice(self.MUMBLE_LAST))
+ print(' '.join(output), file=self.stdout)
+
+
+if __name__ == '__main__':
+ import sys
+ c = CmdLineApp()
+ sys.exit(c.cmdloop())