changeset 345:6fe1e75e3a67

transcript test wasn't running pre and post cmd hooks
author catherine@Drou
date Tue, 16 Feb 2010 15:13:11 -0500
parents 4300ef912f4a
children 49dd1ce6cfd6
files cmd2.py docs/freefeatures.rst docs/pycon2010/pirate6.py docs/pycon2010/pycon2010.rst
diffstat 4 files changed, 85 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Tue Feb 16 14:05:25 2010 -0500
+++ b/cmd2.py	Tue Feb 16 15:13:11 2010 -0500
@@ -1473,8 +1473,11 @@
                 while line.startswith(self.cmdapp.continuation_prompt):
                     command.append(line[len(self.cmdapp.continuation_prompt):])
                     line = transcript.next()
-                command = ''.join(command)
-                self.cmdapp.onecmd(command)
+                command = ''.join(command)               
+                command = self.cmdapp.precmd(command)
+                stop = self.cmdapp.onecmd(command)
+                stop = self.cmdapp.postcmd(stop, command)
+                #TODO: should act on ``stop``
                 result = self.outputTrap.read()
                 if line.startswith(self.cmdapp.prompt):
                     message = '\nFile %s, line %d\nCommand was:\n%s\nExpected: (nothing)\nGot:\n%s\n'%\
--- a/docs/freefeatures.rst	Tue Feb 16 14:05:25 2010 -0500
+++ b/docs/freefeatures.rst	Tue Feb 16 15:13:11 2010 -0500
@@ -5,18 +5,6 @@
 These features are provided "for free" to a cmd_-based application
 simply by replacing ``import cmd`` with ``import cmd2 as cmd``.
 
-Abbreviated commands
-====================
-
-``cmd2`` apps will accept shortened command names
-so long as there is no ambiguity.  Thus, if 
-``do_divide`` is defined, then ``divid``, ``div``,
-or even ``d`` will suffice, so long as there are
-no other commands defined beginning with *divid*,
-*div*, or *d*.
-
-This behavior can be turned off with ``app.abbrev`` (see :ref:`parameters`)
-
 Script files
 ============
 
@@ -30,6 +18,30 @@
 
 .. automethod:: cmd2.Cmd.do_edit
 
+Comments
+========
+
+Comments are omitted from the argument list
+before it is passed to a ``do_`` method.  By
+default, both Python-style and C-style comments
+are recognized; you may change this by overriding
+``app.commentGrammars`` with a different pyparsing_
+grammar.
+
+Comments can be useful in :ref:`script`s.  Used
+in an interactive session, they may indicate
+mental imbalance.
+
+::
+
+    def do_speak(self, arg):
+        self.stdout.write(arg + '\n')
+
+::
+
+  (Cmd) speak it was /* not */ delicious! # Yuck!
+  it was  delicious!
+
 Output redirection
 ==================
 
@@ -128,30 +140,19 @@
 synonyms ``exit`` and simply ``q``).
 It's trivial, but it's one less thing for you to remember.
 
-Comments
-========
 
-Comments are omitted from the argument list
-before it is passed to a ``do_`` method.  By
-default, both Python-style and C-style comments
-are recognized; you may change this by overriding
-``app.commentGrammars`` with a different pyparsing_
-grammar.
+Abbreviated commands
+====================
 
-Comments can be useful in :ref:`script`s.  Used
-in an interactive session, they may indicate
-mental imbalance.
-
-::
+``cmd2`` apps will accept shortened command names
+so long as there is no ambiguity.  Thus, if 
+``do_divide`` is defined, then ``divid``, ``div``,
+or even ``d`` will suffice, so long as there are
+no other commands defined beginning with *divid*,
+*div*, or *d*.
 
-    def do_speak(self, arg):
-        self.stdout.write(arg + '\n')
-
-::
-
-  (Cmd) speak it was /* not */ delicious! # Yuck!
-  it was  delicious!
-  	
+This behavior can be turned off with ``app.abbrev`` (see :ref:`parameters`)
+  
 Misc. pre-defined commands
 ==========================
 
@@ -170,3 +171,5 @@
 
 Transcript-based testing
 ========================
+
+If a ``cmd2``-based application is invoked with --test
\ No newline at end of file
--- a/docs/pycon2010/pirate6.py	Tue Feb 16 14:05:25 2010 -0500
+++ b/docs/pycon2010/pirate6.py	Tue Feb 16 15:13:11 2010 -0500
@@ -1,4 +1,4 @@
-from cmd import Cmd
+from cmd2 import Cmd
 # prompts and defaults
 
 class Pirate(Cmd):
@@ -20,7 +20,7 @@
                 print('''What's "{0}"?  I'll take rrrum.'''.format(arg))
             self.gold -= 1            
     def postcmd(self, stop, line):
-        print('Now we gots {0} doubloons'.format(self.gold)
+        print('Now we gots {0} doubloons'.format(self.gold))
         if self.gold < 0:
             print("Off to debtorrr's prrrison.  Game overrr.")
             return True
--- a/docs/pycon2010/pycon2010.rst	Tue Feb 16 14:05:25 2010 -0500
+++ b/docs/pycon2010/pycon2010.rst	Tue Feb 16 15:13:11 2010 -0500
@@ -36,9 +36,9 @@
 - "Command-line interface"
 - "Shell"
 
-* Accepts free text input at prompt
-* Outputs lines of text
-* Persistent CLI environment
+1. Accepts free text input at prompt
+2. Outputs lines of text
+3. (repeat)
 
 Examples
 ========
@@ -55,9 +55,9 @@
 != Command Line Utilities
 =========================
 
-* Accept arguments at invocation
-* execution
-* terminate
+1. Accepts arguments at invocation
+2. executes
+3. terminates
 
 Examples
 --------
@@ -163,7 +163,8 @@
                 self.gold -= int(arg)
             except:
                 if arg:
-                    print('''What's "{0}"?  I'll take rrrum.'''.format(arg))
+                    print('''What's "{0}"?  I'll take rrrum.'''
+                          .format(arg))
                 self.gold -= 1            
         
 quitting: pirate5.py
@@ -172,7 +173,8 @@
 ::
 
     def postcmd(self, stop, line):
-        print('Now we gots {0} doubloons'.format(self.gold))
+        print('Now we gots {0} doubloons'
+              .format(self.gold))
         if self.gold < 0:
             print("Off to debtorrr's prrrison.  Game overrr.")
             return True
@@ -188,4 +190,35 @@
 
     prompt = 'arrr> '
     def default(self, line):
-        print('What mean ye by "{0}"?'.format(line))
\ No newline at end of file
+        print('What mean ye by "{0}"?'
+              .format(line))
+        
+cmd2
+====
+
+Third-party module in PyPI
+
+What you get
+============
+
+    * Abbreviated commands
+    * Script files
+    * Output redirection
+    * Commands at invocation
+    * Python
+    
+    * Searchable command history
+    * Quitting the application
+    * Comments
+    * Misc. pre-defined commands
+    * Transcript-based testing
+More
+====
+
+    * Case-insensitivity
+    * Shortcuts
+    * Default to shell
+    * Timing
+    * Echo
+    * Debug
+    * Other user-settable parameters