changeset 156:7e5a57df88aa

kinks in assumeComplete
author catherine@dellzilla
date Fri, 21 Nov 2008 17:56:28 -0500
parents 8ba5127167f5
children 10e917acf787
files cmd2.py example/exampleSession.txt
diffstat 2 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Fri Nov 21 17:05:26 2008 -0500
+++ b/cmd2.py	Fri Nov 21 17:56:28 2008 -0500
@@ -355,7 +355,7 @@
         multilineCommand = pyparsing.Or([pyparsing.Keyword(c, caseless=self.caseInsensitive) for c in self.multilineCommands])('multilineCommand')
         oneLineCommand = pyparsing.Word(pyparsing.printables)('command')
         afterElements = \
-            pyparsing.Optional('|' + pyparsing.SkipTo(outputParser ^ stringEnd).setParseAction(lambda x: [y.strip() for y in x])('pipeTo')) + \
+            pyparsing.Optional('|' + pyparsing.SkipTo(outputParser ^ stringEnd)('pipeTo')) + \
             pyparsing.Optional(outputParser + pyparsing.SkipTo(stringEnd).setParseAction(lambda x: x[0].strip())('outputTo'))
         if self.caseInsensitive:
             multilineCommand.setParseAction(lambda x: x[0].lower())
@@ -420,9 +420,13 @@
             return
         try:
             statement = self.parsed(line)
-            while statement.multilineCommand and not (statement.terminator or assumeComplete):
-                statement = self.parsed('%s\n%s' % (statement.raw, 
-                                        self.pseudo_raw_input(self.continuationPrompt)))
+            if assumeComplete:
+                if statement.multilineCommand and not statement.terminator:
+                    statement = self.parsed(statement.raw + self.terminators[0])
+            else:
+                while statement.multilineCommand and not statement.terminator:
+                    statement = self.parsed('%s\n%s' % (statement.raw, 
+                                            self.pseudo_raw_input(self.continuationPrompt)))
         except Exception, e:
             print e
             return 0
@@ -570,7 +574,7 @@
             if (val[0] == val[-1]) and val[0] in ("'", '"'):
                 val = val[1:-1]
             else:                
-                val = cast(currentVal, self.parsed(val).unterminated)
+                val = cast(currentVal, self.parsed(val).statement)
             setattr(self, paramName, val)
             self.stdout.write('%s - was: %s\nnow: %s\n' % (paramName, currentVal, val))
         except (ValueError, AttributeError, NotSettableError), e:
--- a/example/exampleSession.txt	Fri Nov 21 17:05:26 2008 -0500
+++ b/example/exampleSession.txt	Fri Nov 21 17:56:28 2008 -0500
@@ -77,13 +77,12 @@
 OODNIGHT, GRACIEGAY
 OODNIGHT, GRACIEGAY
 OODNIGHT, GRACIEGAY
-(Cmd) orate Four score and
+(Cmd) orate four score and
 > 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
 (Cmd) & look, a shortcut!
 look, a shortcut!
 (Cmd) say put this in a file > myfile.txt