diff cmd2.py @ 134:c28ae4f75c15

incorporated changes from branch at work
author catherine@Elli.myhome.westell.com
date Sat, 08 Nov 2008 21:33:47 -0500
parents 31674148b13c
children 7c0a89fccf2b
line wrap: on
line diff
--- a/cmd2.py	Sat Nov 08 17:10:20 2008 -0500
+++ b/cmd2.py	Sat Nov 08 21:33:47 2008 -0500
@@ -203,6 +203,8 @@
         result = "\n".join('%s: %s' % (sc[0], sc[1]) for sc in self.shortcuts.items())
         self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result))
 
+    commentRemover = (pyparsing.SkipTo(pyparsing.StringEnd()))('fullStatement')
+    commentRemover.suppress(pyparsing.pythonStyleComment)
     specialTerminators = {'/*': pyparsing.Literal('*/')('terminator') }
     terminatorPattern = ((pyparsing.Literal(';') ^ pyparsing.Literal('\n\n'))
                   ^ (pyparsing.Literal('\nEOF') + pyparsing.lineEnd))('terminator')
@@ -243,19 +245,16 @@
         '''
         if isinstance(s, pyparsing.ParseResults):
             return s
-        result = (pyparsing.SkipTo(pyparsing.StringEnd()))('fullStatement').parseString(s)
+        result = self.commentRemover.parseString(s)
         command = s.split()[0]
         if self.caseInsensitive:
             command = command.lower()
-        '''if command in self.noSpecialParse:
-            result['statement'] = result['upToIncluding'] = result['unterminated'] = result.fullStatement
+        if command in self.noSpecialParse:
             result['command'] = command
-            result['args'] = ' '.join(result.fullStatement.split()[1:])
-            return result'''
-        for (shortcut, fullCommand) in self.shortcuts.items():
-            if s.startswith(shortcut):
-                s = s.replace(shortcut, fullCommand + ' ', 1)
-                break
+            result['statement'] = result.fullStatement
+            return result
+        if s[0] in self.shortcuts:
+            s = self.shortcuts[s[0]] + ' ' + s[1:]
         result['statement'] = s
         result['parseable'] = s
         terminator = self.specialTerminators.get(command) or self.terminatorPattern
@@ -349,7 +348,10 @@
             if statekeeper:
                 if statement.output and not statement.outputTo:
                     self.stdout.seek(0)
-                    writeToPasteBuffer(self.stdout.read())
+                    try:
+                        writeToPasteBuffer(self.stdout.read())
+                    except Exception, e:
+                        print str(e)
                 elif statement.pipe:
                     for result in redirect.communicate():              
                         statekeeper.stdout.write(result or '')