diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-24 15:13:54 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-24 15:13:54 -0400 |
commit | d1438e07d48a11ef4405305277422b84cbaef06a (patch) | |
tree | c389f54918a7e232be5ca016f68aed1bba31ef60 | |
parent | da5f03fb515d0a751d356a0f664ccb4b3df83eb1 (diff) | |
download | cmd2-git-d1438e07d48a11ef4405305277422b84cbaef06a.tar.gz |
Removing duplicate functionality by calling runcmds_plus_hooks() to run cmdqueue
-rw-r--r-- | cmd2/cmd2.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 51d5b5b6..d1a5552e 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1840,9 +1840,11 @@ class Cmd(cmd.Cmd): self.perror(ex) def runcmds_plus_hooks(self, cmds: List[str]) -> bool: - """Convenience method to run multiple commands by onecmd_plus_hooks. + """ + Used when commands are being run in an automated fashion like text scripts or history replays. + The prompt and command line for each command will be printed if echo is True. - :param cmds: command strings suitable for onecmd_plus_hooks. + :param cmds: command strings suitable for onecmd_plus_hooks :return: True if running of commands should stop """ for line in cmds: @@ -2272,12 +2274,12 @@ class Cmd(cmd.Cmd): readline.parse_and_bind(self.completekey + ": complete") try: - while True: + stop = False + while not stop: if self.cmdqueue: - # Run command out of cmdqueue if nonempty (populated by load command or commands at invocation) - line = self.cmdqueue.pop(0) - if self.echo: - self.poutput('{}{}'.format(self.prompt, line)) + # Run commands out of cmdqueue if nonempty (populated by commands at invocation) + stop = self.runcmds_plus_hooks(self.cmdqueue) + self.cmdqueue.clear() else: # Otherwise, read a command from stdin try: @@ -2289,9 +2291,8 @@ class Cmd(cmd.Cmd): self.poutput('^C') line = '' - # Run the command along with all associated pre and post hooks - if self.onecmd_plus_hooks(line): - break + # Run the command along with all associated pre and post hooks + stop = self.onecmd_plus_hooks(line) finally: if self.use_rawinput and self.completekey and rl_type != RlType.NONE: |