# HG changeset patch # User catherine@cordelia # Date 1211675433 14400 # Node ID b3200c6e576389b8a33a654022856ae1cc9e6bb7 # Parent 1275d59c08a7d25165b402f2235a7a10950f41c5 inserting exception for quit... diff -r 1275d59c08a7 -r b3200c6e5763 cmd2.py --- a/cmd2.py Thu May 22 20:07:07 2008 -0400 +++ b/cmd2.py Sat May 24 20:30:33 2008 -0400 @@ -125,6 +125,9 @@ raise OSError, pastebufferr % ('xclip', 'On Debian/Ubuntu, install with "sudo apt-get install xclip"') setPasteBuffer = getPasteBuffer +class ExitException(Exception): + pass + class Cmd(cmd.Cmd): caseInsensitive = True multilineCommands = [] @@ -134,6 +137,7 @@ defaultExtension = 'txt' defaultFileName = 'command.txt' editor = os.environ.get('EDITOR') + _STOP_AND_EXIT = 2 if not editor: if sys.platform[:3] == 'win': editor = 'notepad' @@ -336,6 +340,7 @@ readline.set_completer(self.old_completer) except ImportError: pass + return stop def do_EOF(self, arg): return True @@ -370,7 +375,7 @@ self.stdout.write('%s: %s\n' % (param, str(getattr(self, param)))) def do_quit(self, arg): - return 1 + raise ExitException do_exit = do_quit do_q = do_quit @@ -501,10 +506,12 @@ return self.use_rawinput = False self.prompt = self.continuationPrompt = '' - self.cmdloop() + stop = self.cmdloop() + # but how to detect whether to exit totally? self.stdin.close() keepstate.restore() self.lastcmd = '' + return (stop == self._STOP_AND_EXIT) def do_run(self, arg): """run [arg]: re-runs an earlier command