Skip to content

Commit ba1319f

Browse files
committed
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.
1 parent 164ed17 commit ba1319f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

cmd2.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,14 +1017,13 @@ def _cmdloop(self):
10171017
if self.cmdqueue:
10181018
# Run command out of cmdqueue if nonempty (populated by load command or commands at invocation)
10191019
line = self.cmdqueue.pop(0)
1020+
1021+
if self.echo and line != 'eos':
1022+
self.poutput('{}{}'.format(self.prompt, line))
10201023
else:
10211024
# Otherwise, read a command from stdin
10221025
line = self.pseudo_raw_input(self.prompt)
10231026

1024-
# If echo is on and in the middle of running a script, then echo the line to the output
1025-
if self.echo and self._current_script_dir is not None:
1026-
self.poutput(line + '\n')
1027-
10281027
# Run the command along with all associated pre and post hooks
10291028
stop = self.onecmd_plus_hooks(line)
10301029
finally:

tests/test_cmd2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,8 @@ def test_echo(capsys):
13721372
app = cmd2.Cmd()
13731373
# Turn echo on and pre-stage some commands in the queue, simulating like we are in the middle of a script
13741374
app.echo = True
1375-
app.cmdqueue = ['help history', 'quit', 'eos']
1375+
command = 'help history'
1376+
app.cmdqueue = [command, 'quit', 'eos']
13761377
app._script_dir.append('some_dir')
13771378

13781379
assert app._current_script_dir is not None
@@ -1385,7 +1386,7 @@ def test_echo(capsys):
13851386
# Check the output
13861387
assert app.cmdqueue == []
13871388
assert app._current_script_dir is None
1388-
assert out.startswith('help history\n' + 'history [arg]: lists past commands issued')
1389+
assert out.startswith('{}{}\n'.format(app.prompt, command) + 'history [arg]: lists past commands issued')
13891390

13901391

13911392
def test_raw_input(base_app):

0 commit comments

Comments
 (0)