diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-02-15 19:42:45 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-02-15 19:42:45 -0500 |
commit | 658777ce0dd2df1a1747d85a44aef87a2d5e6747 (patch) | |
tree | 256b4929da4014d9dd0d1c1e832444be0ffcfbef /cmd2.py | |
parent | 65aa0436a7bf72ff17f59811c14385219917de67 (diff) | |
download | cmd2-git-658777ce0dd2df1a1747d85a44aef87a2d5e6747.tar.gz |
Fixed how commands at invocation are dealt with.
Now the preloop() runs and the intro prints prior to executing any commands supplied as arguments on the command line.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -1119,7 +1119,7 @@ class Cmd(cmd.Cmd): line = line[:-1] return line - def _cmdloop(self, intro=None): + def _cmdloop(self): """Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument. @@ -1136,8 +1136,6 @@ class Cmd(cmd.Cmd): pass stop = None try: - if intro is not None: - self.stdout.write(str(self.intro) + "\n") while not stop: if self.cmdqueue: line = self.cmdqueue.pop(0) @@ -1576,7 +1574,7 @@ relative to the already-running script's directory. self.use_rawinput = False self.prompt = self.continuation_prompt = '' self.current_script_dir = os.path.split(targetname)[0] - stop = self._cmdloop(None) + stop = self._cmdloop() self.stdin.close() keepstate.restore() self.lastcmd = '' @@ -1645,10 +1643,24 @@ Script should contain one command per line, just like command would be typed in if callopts.test: self.runTranscriptTests(callargs) else: + # Always run the preloop first + self.preloop() + + # If an intro was supplied in the method call, allow it to override the default + if intro is not None: + self.intro = intro + + # Print the intro, if there is one, right after the preloop + if self.intro is not None: + self.stdout.write(str(self.intro) + "\n") + + # Process any commands present as arguments on the command-line if not self.run_commands_at_invocation(callargs): - self.preloop() - self._cmdloop(self.intro) - self.postloop() + # And then call _cmdloop() if there wasn't something in those causing us to quit + self._cmdloop() + + # Run the postloop() no matter what + self.postloop() class HistoryItem(str): |