diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-07-20 23:33:52 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-07-20 23:33:52 -0400 |
commit | 13936653ec86ba405f29f6a680e91a7f21353aaa (patch) | |
tree | dca3fb3f03b8905fc1ccbbd7429a365911da959a /cmd2/cmd2.py | |
parent | d87459756e368b4c61a35808078373a58fcadc5a (diff) | |
download | cmd2-git-13936653ec86ba405f29f6a680e91a7f21353aaa.tar.gz |
Added pwarning()
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index a74b6c30..4553e2cd 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -652,6 +652,14 @@ class Cmd(cmd.Cmd): final_msg = "{}".format(msg) ansi.ansi_aware_write(sys.stderr, final_msg + end) + def pwarning(self, msg: Any, *, end: str = '\n') -> None: + """Apply the warning style to a message and print it to sys.stderr + + :param msg: message to print (anything convertible to a str with '{}'.format() is OK) + :param end: string appended after the end of the message, default a newline + """ + self.perror(ansi.style_warning(msg), end=end, apply_style=False) + def pexcept(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> None: """Print Exception message to sys.stderr. If debug is true, print exception traceback if one exists. @@ -3659,7 +3667,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), apply_style=False) + self.pwarning(warning) # finally, we can write the transcript out to the file try: @@ -3749,8 +3757,7 @@ class Cmd(cmd.Cmd): 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) + self.pwarning("'{}' appears to be a Python file".format(expanded_path)) selection = self.select('Yes No', 'Continue to try to run it as a text file script? ') if selection != 'Yes': return |