summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2019-07-14 21:31:23 -0600
committerkotfu <kotfu@kotfu.net>2019-07-14 21:31:23 -0600
commit9325989ae5c7aa463b34bdc6997445a9603030d4 (patch)
tree84cbbbd8131aa3bc98a9b73b96532551c998e532 /examples
parentaa34722a54e2ccfd2b831624e6219464e520d834 (diff)
downloadcmd2-git-9325989ae5c7aa463b34bdc6997445a9603030d4.tar.gz
Finish migration documentation for #719
Diffstat (limited to 'examples')
-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())