changeset 165:3dc882a00e53

terminators + suffixes now preserved
author catherine@dellzilla
date Thu, 04 Dec 2008 16:43:57 -0500
parents 5209d230f96b
children a3414ac38677
files cmd2.py
diffstat 1 files changed, 19 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Thu Dec 04 14:01:16 2008 -0500
+++ b/cmd2.py	Thu Dec 04 16:43:57 2008 -0500
@@ -61,7 +61,7 @@
                 return
             if hasattr(opts, '_exit'):
                 return None
-            arg = arg.parser('%s %s' % (arg.parsed.command, newArgs))
+            arg = arg.parser('%s %s%s%s' % (arg.parsed.command, newArgs, arg.parsed.terminator, arg.parsed.suffix))
             result = func(instance, arg, opts)                            
             return result        
         newFunc.__doc__ = '%s\n%s' % (func.__doc__, optionParser.format_help())
@@ -405,27 +405,25 @@
         self.inputParser = inputMark + pyparsing.Optional(inputFrom)
         self.inputParser.ignore(pyparsing.sglQuotedString).ignore(pyparsing.dblQuotedString).ignore(self.commentGrammars).ignore(self.commentInProgress)               
     
-    def parsed(self, raw, useTerminatorFrom=None):
+    def parsed(self, raw, **kwargs):
         if isinstance(raw, ParsedString):
-            if useTerminatorFrom:
-                raw['terminator'] = useTerminatorFrom.parsed.terminator
-                raw['suffix'] = useTerminatorFrom.parsed.suffix
-            return raw           
-        s = self.inputParser.transformString(raw.strip())
-        for (shortcut, expansion) in self.shortcuts.items():
-            if s.startswith(shortcut):
-                s = s.replace(shortcut, expansion + ' ', 1)
-                break
-        result = self.parser.parseString(s)
-        result['command'] = result.multilineCommand or result.command        
-        if useTerminatorFrom:
-            return self.parsed('%s %s%s%s' % (result.command, result.args, useTerminatorFrom.parsed.terminator, useTerminatorFrom.parsed.suffix))
-        result['raw'] = raw
-        result['clean'] = self.commentGrammars.transformString(result.args)
-        result['expanded'] = s        
-        p = ParsedString(result.args)
-        p.parsed = result
-        p.parser = self.parsed
+            p = raw
+        else:
+            s = self.inputParser.transformString(raw.strip())
+            for (shortcut, expansion) in self.shortcuts.items():
+                if s.startswith(shortcut):
+                    s = s.replace(shortcut, expansion + ' ', 1)
+                    break
+            result = self.parser.parseString(s)
+            result['command'] = result.multilineCommand or result.command        
+            result['raw'] = raw
+            result['clean'] = self.commentGrammars.transformString(result.args)
+            result['expanded'] = s        
+            p = ParsedString(result.args)
+            p.parsed = result
+            p.parser = self.parsed
+        for (key, val) in kwargs.items():
+            p.parsed[key] = val
         return p
               
     def onecmd(self, line, assumeComplete=False):