summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/cmd2.py2
-rw-r--r--tests/test_plugin.py24
2 files changed, 25 insertions, 1 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 51f2f924..946182c9 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1840,7 +1840,7 @@ class Cmd(cmd.Cmd):
pipe runs out. We can't refactor it because we need to retain
backwards compatibility with the standard library version of cmd.
"""
- statement = self.statement_parser.parse(line)
+ statement = self.statement_parser.parse(self.preparse(line))
while statement.multiline_command and not statement.terminator:
if not self.quit_on_sigint:
try:
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index fd8609c3..e401e837 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -22,6 +22,7 @@ class Plugin:
self.reset_counters()
def reset_counters(self):
+ self.called_preparse = 0
self.called_postparsing = 0
self.called_precmd = 0
self.called_postcmd = 0
@@ -51,6 +52,16 @@ class Plugin:
###
#
+ # preparse hook
+ #
+ ###
+ def preparse(self, line: str) -> str:
+ "Preparsing hook"
+ self.called_preparse += 1
+ return line
+
+ ###
+ #
# Postparsing hooks
#
###
@@ -310,6 +321,19 @@ def test_postloop_hooks(capsys):
###
#
+# test preparse hook
+#
+###
+def test_preparse(capsys):
+ app = PluggedApp()
+ app.onecmd_plus_hooks('say hello')
+ out, err = capsys.readouterr()
+ assert out == 'hello\n'
+ assert not err
+ assert app.called_preparse == 1
+
+###
+#
# test postparsing hooks
#
###