summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatherine Devlin <catherine.devlin@gmail.com>2008-12-04 16:43:57 -0500
committerCatherine Devlin <catherine.devlin@gmail.com>2008-12-04 16:43:57 -0500
commit28ac76b6bf062b5c4a4036e8457f8bf2f876fcbd (patch)
tree7a93f4c151d4f6a3a3cecfb86ca54d4a68807c2a
parentf475c7a5655a3a6999475d07f0aec7f2b2d0fc27 (diff)
downloadcmd2-git-28ac76b6bf062b5c4a4036e8457f8bf2f876fcbd.tar.gz
terminators + suffixes now preserved
-rwxr-xr-xcmd2.py40
1 files changed, 19 insertions, 21 deletions
diff --git a/cmd2.py b/cmd2.py
index b2d4dd2e..c5c2a5c3 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -61,7 +61,7 @@ def options(option_list):
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 @@ class Cmd(cmd.Cmd):
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):