Mercurial > sqlpython
changeset 35:e2a5cdba3113
moved from precmd and postcmd into onecmd
author | devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil |
---|---|
date | Fri, 21 Dec 2007 16:17:06 -0500 |
parents | d3b2f9c6e536 |
children | 6315f75c45ae |
files | cmd2.py |
diffstat | 1 files changed, 18 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd2.py Fri Dec 21 16:01:52 2007 -0500 +++ b/cmd2.py Fri Dec 21 16:17:06 2007 -0500 @@ -7,9 +7,9 @@ Load commands from file Settable environment parameters -still to do: +todo: edit spits eof -run +flags > """ import cmd, re, os, sys @@ -43,12 +43,16 @@ cmd.Cmd.__init__(self, *args, **kwargs) self.history = History() - def precmd(self, line): - """Hook method executed just before the command line is - interpreted, but after the input prompt is generated and issued. - - Makes commands case-insensitive (but unfortunately does not alter command completion). - """ + def onecmd(self, line): + """Interpret the argument as though it had been typed in response + to the prompt. + + This may be overridden, but should not normally need to be; + see the precmd() and postcmd() methods for useful execution hooks. + The return value is a flag indicating whether interpretation of + commands by the interpreter should stop. + + """ try: (command, args) = line.split(None,1) except ValueError: @@ -56,18 +60,15 @@ if self.caseInsensitive: command = command.lower() statement = ' '.join([command, args]) - if (not self.multilineCommands) or (command not in self.multilineCommands): - return statement - return self.finishStatement(statement) - - def postcmd(self, stop, line): - """Hook method executed just after a command dispatch is finished.""" + if command in self.multilineCommands: + statement = self.finishStatement(statement) + stop = cmd.Cmd.onecmd(self, statement) try: - command = line.split(None,1)[0].lower() + command = statement.split(None,1)[0].lower() if command not in self.excludeFromHistory: - self.history.append(line) + self.history.append(statement) finally: - return stop + return stop def finishStatement(self, firstline): statement = firstline