diff options
author | TL <tleonhardt@sigovs.com> | 2017-01-11 12:22:19 -0500 |
---|---|---|
committer | TL <tleonhardt@sigovs.com> | 2017-01-11 12:22:19 -0500 |
commit | 30e55d72351b367a1c303cc1d52c2bfaf950ccec (patch) | |
tree | 473cb399123072009491e2826ed6d5137b1b5e98 /example/example.py | |
parent | 1d3bd562aa69dc50249974fd96dfd39d6dd28c7c (diff) | |
download | cmd2-git-30e55d72351b367a1c303cc1d52c2bfaf950ccec.tar.gz |
Fixed example.py and exampleSession.txt so that the example runs and the test passes when running "python example.py -t exampleSession.txt".
Also made the front-page documentation consistent so it references the actual code and text in this modified example.
Diffstat (limited to 'example/example.py')
-rwxr-xr-x | example/example.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/example/example.py b/example/example.py index 863084cd..782c5e23 100755 --- a/example/example.py +++ b/example/example.py @@ -1,26 +1,36 @@ +#!/usr/bin/env python # coding=utf-8 """A sample application for cmd2. + +Thanks to cmd2's built-in transtript testing capability, it also serves as a test suite for example.py when used with + the exampleSession.txt transcript. + +Running `python example.py -t exampleSession.txt` will run all the commands in the transcript against example.py, +verifying that the output produced matches the transcript. """ from cmd2 import Cmd, make_option, options class CmdLineApp(Cmd): + """ Example cmd2 application. """ multilineCommands = ['orate'] - Cmd.shortcuts.update({'&': 'speak', 'h': 'hello'}) + Cmd.shortcuts.update({'&': 'speak'}) maxrepeats = 3 - redirector = '->' - Cmd.settable.append('maxrepeats Max number of `--repeat`s allowed') + Cmd.settable.append('maxrepeats') + + # Setting this true makes it run a shell command if a cmd2/cmd command doesn't exist + # default_to_shell = True @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"), make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"), make_option('-r', '--repeat', type="int", help="output [n] times") - ], arg_desc='(text to say)') + ]) def do_speak(self, arg, opts=None): """Repeats what you tell me to.""" arg = ''.join(arg) if opts.piglatin: - arg = '%s%say' % (arg[1:].rstrip(), arg[0]) + arg = '%s%say' % (arg[1:], arg[0]) if opts.shout: arg = arg.upper() repetitions = opts.repeat or 1 @@ -34,5 +44,6 @@ class CmdLineApp(Cmd): do_orate = do_speak # another synonym, but this one takes multi-line input -c = CmdLineApp() -c.cmdloop() +if __name__ == '__main__': + c = CmdLineApp() + c.cmdloop() |