diff options
-rw-r--r-- | cmd2/cmd2.py | 15 | ||||
-rw-r--r-- | tests/test_transcript.py | 7 |
2 files changed, 11 insertions, 11 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 8106891a..d2610cc3 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3428,7 +3428,7 @@ class Cmd(cmd.Cmd): except Exception as e: self.perror('Saving {!r} - {}'.format(args.output_file, e), traceback_war=False) elif args.transcript: - return self._generate_transcript(history, args.transcript) + self._generate_transcript(history, args.transcript) else: # Display the history items retrieved for hi in history: @@ -3507,10 +3507,9 @@ class Cmd(cmd.Cmd): msg = "can not write persistent history file '{}': {}" self.perror(msg.format(self.persistent_history_file, ex), traceback_war=False) - def _generate_transcript(self, history: List[Union[HistoryItem, str]], transcript_file: str) -> Optional[bool]: + def _generate_transcript(self, history: List[Union[HistoryItem, str]], transcript_file: str) -> None: """ Generate a transcript file from a given history of commands - :return: True if running of commands should stop """ # Validate the transcript file path to make sure directory exists and write access is available transcript_path = os.path.abspath(os.path.expanduser(transcript_file)) @@ -3521,7 +3520,6 @@ class Cmd(cmd.Cmd): return commands_run = 0 - stop = False try: with self.sigint_protection: # Disable echo while we manually redirect stdout to a StringIO buffer @@ -3573,6 +3571,11 @@ class Cmd(cmd.Cmd): self.echo = saved_echo self.stdout = saved_stdout + # Check if all commands ran + if commands_run < len(history): + warning = "Command {} triggered a stop and ended transcript generation early".format(commands_run) + self.perror(warning, err_color=constants.WARNING_COLOR, traceback_war=False) + # finally, we can write the transcript out to the file try: with open(transcript_file, 'w') as fout: @@ -3588,8 +3591,6 @@ class Cmd(cmd.Cmd): msg = '{} {} saved to transcript file {!r}' self.pfeedback(msg.format(commands_run, plural, transcript_file)) - return stop - edit_description = ("Edit a file in a text editor\n" "\n" "The editor used is determined by a settable parameter. To set it:\n" @@ -3677,7 +3678,7 @@ class Cmd(cmd.Cmd): self._script_dir.append(os.path.dirname(expanded_path)) if args.transcript: - return self._generate_transcript(script_commands, os.path.expanduser(args.transcript)) + self._generate_transcript(script_commands, os.path.expanduser(args.transcript)) else: return self.runcmds_plus_hooks(script_commands) diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 4142e386..ed4c2755 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -231,12 +231,11 @@ def test_generate_transcript_stop(capsys): assert not stop assert err.startswith("2 commands") - # Since quit returns True for stop, only the first 2 commands will run and stop should be True + # Since quit returns True for stop, only the first 2 commands will run commands = ['help', 'quit', 'alias'] - stop = app._generate_transcript(commands, transcript_fname) + app._generate_transcript(commands, transcript_fname) _, err = capsys.readouterr() - assert stop - assert err.startswith("2 commands") + assert "triggered a stop" in err @pytest.mark.parametrize('expected, transformed', [ |