summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/cmd2.py2
-rw-r--r--cmd2/history.py4
-rwxr-xr-xexamples/cmd_as_argument.py3
-rw-r--r--tests/test_history.py31
-rw-r--r--tests/test_parsing.py12
5 files changed, 48 insertions, 4 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 387fe6d9..4c1a1bb6 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1934,7 +1934,7 @@ class Cmd(cmd.Cmd):
break
# This will be true when a macro was used
- if orig_line != statement.raw:
+ if not statement.multiline_command and orig_line != statement.raw:
# Build a Statement that contains the resolved macro line
# but the originally typed line for its raw member.
statement = Statement(statement.args,
diff --git a/cmd2/history.py b/cmd2/history.py
index bbeb9199..7ec4ce7b 100644
--- a/cmd2/history.py
+++ b/cmd2/history.py
@@ -44,9 +44,9 @@ class HistoryItem():
:return: pretty print string version of a HistoryItem
"""
if verbose:
- ret_str = self._listformat.format(self.idx, self.raw)
+ ret_str = self._listformat.format(self.idx, self.raw.rstrip())
if self.raw != self.expanded.rstrip():
- ret_str += self._ex_listformat.format(self.idx, self.expanded)
+ ret_str += self._ex_listformat.format(self.idx, self.expanded.rstrip())
else:
if script:
# display without entry numbers
diff --git a/examples/cmd_as_argument.py b/examples/cmd_as_argument.py
index 9eb0befb..bd7f00cb 100755
--- a/examples/cmd_as_argument.py
+++ b/examples/cmd_as_argument.py
@@ -31,9 +31,10 @@ class CmdLineApp(cmd2.Cmd):
shortcuts = dict(self.DEFAULT_SHORTCUTS)
shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
- super().__init__(use_ipython=False, multiline_commands=['orate'], shortcuts=shortcuts)
+ super().__init__(use_ipython=True, multiline_commands=['orate'], shortcuts=shortcuts)
self.allow_cli_args = False
+ self.locals_in_py = True
self.maxrepeats = 3
# Make maxrepeats settable at runtime
self.settable['maxrepeats'] = 'max repetitions for speak command'
diff --git a/tests/test_history.py b/tests/test_history.py
index 5e01688c..ce915d1a 100644
--- a/tests/test_history.py
+++ b/tests/test_history.py
@@ -10,6 +10,8 @@ import pytest
# Python 3.5 had some regressions in the unitest.mock module, so use
# 3rd party mock if available
+from cmd2.parsing import StatementParser
+
try:
import mock
except ImportError:
@@ -262,6 +264,35 @@ def histitem():
histitem = HistoryItem(statement, 1)
return histitem
+@pytest.fixture
+def parser():
+ from cmd2.parsing import StatementParser
+ parser = StatementParser(
+ allow_redirection=True,
+ terminators=[';', '&'],
+ multiline_commands=['multiline'],
+ aliases={'helpalias': 'help',
+ '42': 'theanswer',
+ 'l': '!ls -al',
+ 'anothermultiline': 'multiline',
+ 'fake': 'pyscript'},
+ shortcuts=[('?', 'help'), ('!', 'shell')]
+ )
+ return parser
+
+def test_multiline_histitem(parser):
+ from cmd2.history import History
+ line = 'multiline foo\nbar\n\n'
+ statement = parser.parse(line)
+ history = History()
+ history.append(statement)
+ assert len(history) == 1
+ hist_item = history[0]
+ assert hist_item.raw == line
+ pr_lines = hist_item.pr(verbose=True).splitlines()
+ assert pr_lines[0].endswith('multiline foo')
+ assert pr_lines[1] == 'bar'
+
def test_history_item_instantiate():
from cmd2.parsing import Statement
from cmd2.history import HistoryItem
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index de8d67af..9b2fd25b 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -489,6 +489,18 @@ def test_parse_unfinished_multiliine_command(parser):
assert statement.arg_list == statement.argv[1:]
assert statement.terminator == ''
+def test_parse_basic_multiline_command(parser):
+ line = 'multiline foo\nbar\n\n'
+ statement = parser.parse(line)
+ assert statement.multiline_command == 'multiline'
+ assert statement.command == 'multiline'
+ assert statement == 'foo bar'
+ assert statement.args == statement
+ assert statement.argv == ['multiline', 'foo', 'bar']
+ assert statement.arg_list == ['foo', 'bar']
+ assert statement.raw == line
+ assert statement.terminator == '\n'
+
@pytest.mark.parametrize('line,terminator',[
('multiline has > inside;', ';'),
('multiline has > inside;;;', ';'),