diff options
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 15 |
1 files changed, 8 insertions, 7 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) |