summaryrefslogtreecommitdiff
path: root/README.rst
diff options
context:
space:
mode:
authorTL <tleonhardt@sigovs.com>2017-01-11 12:22:19 -0500
committerTL <tleonhardt@sigovs.com>2017-01-11 12:22:19 -0500
commit30e55d72351b367a1c303cc1d52c2bfaf950ccec (patch)
tree473cb399123072009491e2826ed6d5137b1b5e98 /README.rst
parent1d3bd562aa69dc50249974fd96dfd39d6dd28c7c (diff)
downloadcmd2-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 'README.rst')
-rwxr-xr-xREADME.rst58
1 files changed, 29 insertions, 29 deletions
diff --git a/README.rst b/README.rst
index 7f8db6cb..77caf91e 100755
--- a/README.rst
+++ b/README.rst
@@ -88,8 +88,7 @@ Example cmd2 application (example/example.py) ::
'''A sample application for cmd2.'''
- from cmd2 import Cmd, make_option, options, Cmd2TestCase
- import unittest, optparse, sys
+ from cmd2 import Cmd, make_option, options
class CmdLineApp(Cmd):
multilineCommands = ['orate']
@@ -97,6 +96,9 @@ Example cmd2 application (example/example.py) ::
maxrepeats = 3
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")
@@ -118,24 +120,14 @@ Example cmd2 application (example/example.py) ::
do_say = do_speak # now "say" is a synonym for "speak"
do_orate = do_speak # another synonym, but this one takes multi-line input
- class TestMyAppCase(Cmd2TestCase):
- CmdApp = CmdLineApp
- transcriptFileName = 'exampleSession.txt'
-
- parser = optparse.OptionParser()
- parser.add_option('-t', '--test', dest='unittests', action='store_true', default=False, help='Run unit test suite')
- (callopts, callargs) = parser.parse_args()
- if callopts.unittests:
- sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main()
- unittest.main()
- else:
- app = CmdLineApp()
- app.cmdloop()
+ if __name__ == '__main__':
+ c = CmdLineApp()
+ c.cmdloop()
The following is a sample session running example.py.
-Thanks to `TestMyAppCase(Cmd2TestCase)`, it also serves as a test
+Thanks to Cmd2's built-in transcript testing capability, it also serves as a test
suite for example.py when saved as `exampleSession.txt`.
-Running `python example.py -t` will run all the commands in the
+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.
@@ -145,12 +137,13 @@ example/exampleSession.txt::
Documented commands (type help <topic>):
========================================
- _load edit history li load pause run say shell show
- ed hi l list orate r save set shortcuts speak
+ _load ed history list pause run set show
+ _relative_load edit l load py save shell speak
+ cmdenvironment hi li orate r say shortcuts
Undocumented commands:
======================
- EOF cmdenvironment eof exit help q quit
+ EOF eof exit help q quit
(Cmd) help say
Repeats what you tell me to.
@@ -170,10 +163,19 @@ example/exampleSession.txt::
OODNIGHT, GRACIEGAY
OODNIGHT, GRACIEGAY
(Cmd) set
- prompt: (Cmd)
- editor: gedit
+ abbrev: True
+ case_insensitive: True
+ colors: True
+ continuation_prompt: >
+ debug: False
+ default_file_name: command.txt
echo: False
+ editor: gedit
+ feedback_to_output: False
maxrepeats: 3
+ prompt: (Cmd)
+ quiet: False
+ timing: False
(Cmd) set maxrepeats 5
maxrepeats - was: 3
now: 5
@@ -200,6 +202,7 @@ example/exampleSession.txt::
say -ps --repeat=5 goodnight, Gracie
(Cmd) run 4
say -ps --repeat=5 goodnight, Gracie
+
OODNIGHT, GRACIEGAY
OODNIGHT, GRACIEGAY
OODNIGHT, GRACIEGAY
@@ -209,17 +212,14 @@ example/exampleSession.txt::
> seven releases ago
> our BDFL
> blah blah blah
- >
- >
- Four score and seven releases ago our BDFL blah blah blah
+ Four score and
+ seven releases ago
+ our BDFL
+ blah blah blah
(Cmd) & look, a shortcut!
look, a shortcut!
- (Cmd) say put this in a file > myfile.txt
- (Cmd) say < myfile.txt
- put this in a file
(Cmd) set prompt "---> "
prompt - was: (Cmd)
now: --->
---> say goodbye
goodbye
-