diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-07-20 23:28:06 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-07-20 23:28:06 -0400 |
commit | d87459756e368b4c61a35808078373a58fcadc5a (patch) | |
tree | 0f6441b70ff96ea8b399ffe81d25f1aaec84bc0a /cmd2/cmd2.py | |
parent | 882fa3902f855a4ae9ff83f818ac50fe35fb281d (diff) | |
download | cmd2-git-d87459756e368b4c61a35808078373a58fcadc5a.tar.gz |
Print warning if a user tries to run a *.py file with run_script and ask them if they want to continue
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index f2da5927..a74b6c30 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3659,7 +3659,7 @@ class Cmd(cmd.Cmd): # 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(ansi.style_warning(warning)) + self.perror(ansi.style_warning(warning), apply_style=False) # finally, we can write the transcript out to the file try: @@ -3748,6 +3748,13 @@ class Cmd(cmd.Cmd): self.perror("'{}' is not an ASCII or UTF-8 encoded text file".format(expanded_path)) return + if expanded_path.endswith('.py') or expanded_path.endswith('.pyc'): + self.perror(ansi.style_warning("'{}' appears to be a Python file".format(expanded_path)), + apply_style=False) + selection = self.select('Yes No', 'Continue to try to run it as a text file script? ') + if selection != 'Yes': + return + try: # Read all lines of the script with open(expanded_path, encoding='utf-8') as target: |