# HG changeset patch # User devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil # Date 1198271826 18000 # Node ID e2a5cdba31136c9e27aed6a681b7a2d23d920c89 # Parent d3b2f9c6e5364acb96b4f41e5370e49a3fbfa8ab moved from precmd and postcmd into onecmd diff -r d3b2f9c6e536 -r e2a5cdba3113 cmd2.py --- 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