summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-08-23 08:28:19 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-08-23 08:28:19 -0400
commitba1319f22f9e116a12d525d8d1d50cfe6318db4c (patch)
treea9337c84bec69eae0466369b26ecec82059055ff
parent164ed174cff272e94a6092e24c6b0d4ab18fbbe4 (diff)
downloadcmd2-git-ba1319f22f9e116a12d525d8d1d50cfe6318db4c.tar.gz
Improved what gets printed when running commands from a script with load command and echo is True
Previously just the command get printed. Now the prompt and the command gets printed.
-rwxr-xr-xcmd2.py7
-rw-r--r--tests/test_cmd2.py5
2 files changed, 6 insertions, 6 deletions
diff --git a/cmd2.py b/cmd2.py
index 2b43e1ae..d22ce41c 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1017,14 +1017,13 @@ class Cmd(cmd.Cmd):
if self.cmdqueue:
# Run command out of cmdqueue if nonempty (populated by load command or commands at invocation)
line = self.cmdqueue.pop(0)
+
+ if self.echo and line != 'eos':
+ self.poutput('{}{}'.format(self.prompt, line))
else:
# Otherwise, read a command from stdin
line = self.pseudo_raw_input(self.prompt)
- # If echo is on and in the middle of running a script, then echo the line to the output
- if self.echo and self._current_script_dir is not None:
- self.poutput(line + '\n')
-
# Run the command along with all associated pre and post hooks
stop = self.onecmd_plus_hooks(line)
finally:
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 51421bcb..dcbb99f7 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1372,7 +1372,8 @@ def test_echo(capsys):
app = cmd2.Cmd()
# Turn echo on and pre-stage some commands in the queue, simulating like we are in the middle of a script
app.echo = True
- app.cmdqueue = ['help history', 'quit', 'eos']
+ command = 'help history'
+ app.cmdqueue = [command, 'quit', 'eos']
app._script_dir.append('some_dir')
assert app._current_script_dir is not None
@@ -1385,7 +1386,7 @@ def test_echo(capsys):
# Check the output
assert app.cmdqueue == []
assert app._current_script_dir is None
- assert out.startswith('help history\n' + 'history [arg]: lists past commands issued')
+ assert out.startswith('{}{}\n'.format(app.prompt, command) + 'history [arg]: lists past commands issued')
def test_raw_input(base_app):