diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-15 10:05:04 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-15 10:05:04 -0400 |
commit | a1be014e621bd1b9407cfb1eeefdd95ff67dd815 (patch) | |
tree | 29d0d1134129dc55e64f8298e6c5acb691aa9765 | |
parent | 3c0a31399ced7f6e9eb0d63a6c073b27d42034ff (diff) | |
download | cmd2-git-a1be014e621bd1b9407cfb1eeefdd95ff67dd815.tar.gz |
Print warnings at end of load or pyscript instead of beginning
This is in case the user runs a long script - I don't want the warning to quickly scroll off the screen where they then never see it.
-rwxr-xr-x | README.md | 2 | ||||
-rw-r--r-- | cmd2/cmd2.py | 22 |
2 files changed, 11 insertions, 13 deletions
@@ -41,7 +41,7 @@ Main Features - Support for Python 3.5+ on Windows, macOS, and Linux - Trivial to provide built-in help for all commands - Built-in regression testing framework for your applications (transcript-based testing) -- Transcripts for use with built-in regression can be automatically generated from `history -t` or `load -t` +- Transcripts for use with built-in regression can be automatically generated from `history -t` or `run_script -t` - Alerts that seamlessly print while user enters text at prompt Python 2.7 support is EOL diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 93100c5d..1d678180 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -429,8 +429,7 @@ class Cmd(cmd.Cmd): # Built-in commands don't make use of this. It is purely there for user-defined commands and convenience. self._last_result = None - # Used by run_script command to store the current script dir as - # a LIFO queue to support _relative_run_script command + # Used by run_script command to store current script dir as a LIFO queue to support _relative_run_script command self._script_dir = [] # Context manager used to protect critical sections in the main thread from stopping due to a KeyboardInterrupt @@ -3251,11 +3250,6 @@ class Cmd(cmd.Cmd): @with_argparser(run_pyscript_parser) def do_run_pyscript(self, args: argparse.Namespace) -> bool: """Run a Python script file inside the console""" - if args.__statement__.command == "pyscript": - self.perror("pyscript has been renamed and will be removed in the next release, " - "please use run_pyscript instead\n", - traceback_war=False, err_color=Fore.LIGHTYELLOW_EX) - script_path = os.path.expanduser(args.script_path) py_return = False @@ -3277,6 +3271,11 @@ class Cmd(cmd.Cmd): # Restore command line arguments to original state sys.argv = orig_args + if args.__statement__.command == "pyscript": + self.perror("pyscript has been renamed and will be removed in the next release, " + "please use run_pyscript instead\n", + traceback_war=False, err_color=Fore.LIGHTYELLOW_EX) + return py_return # pyscript is deprecated @@ -3654,11 +3653,6 @@ class Cmd(cmd.Cmd): Run commands in script file that is encoded as either ASCII or UTF-8 text :return: True if running of commands should stop """ - if args.__statement__.command == "load": - self.perror("load has been renamed and will be removed in the next release, " - "please use run_script instead\n", - traceback_war=False, err_color=Fore.LIGHTYELLOW_EX) - expanded_path = os.path.abspath(os.path.expanduser(args.script_path)) # Make sure the path exists and we can access it @@ -3704,6 +3698,10 @@ class Cmd(cmd.Cmd): # Check if a script dir was added before an exception occurred if orig_script_dir_count != len(self._script_dir): self._script_dir.pop() + if args.__statement__.command == "load": + self.perror("load has been renamed and will be removed in the next release, " + "please use run_script instead\n", + traceback_war=False, err_color=Fore.LIGHTYELLOW_EX) # load has been deprecated do_load = do_run_script |