# HG changeset patch # User catherine@localhost # Date 1211302565 14400 # Node ID 71151157ac7cc8d594e3c465fd8271b92f6e0a06 # Parent 6d715d7a04fd402cce7fafe95c52fda807846a8e cleaned up: proper exit after -h, -v diff -r 6d715d7a04fd -r 71151157ac7c cmd2.py --- a/cmd2.py Tue May 20 12:54:54 2008 -0400 +++ b/cmd2.py Tue May 20 12:56:05 2008 -0400 @@ -21,34 +21,11 @@ import cmd, re, os, sys, optparse, subprocess, tempfile from optparse import make_option -class Option(optparse.Option): - # optparse.Option.take_action keeps trying to use sys.exit. That's very rude. - # We don't want to exit, we just want to know so we can terminate a particular - # function call. - def take_action(self, action, dest, opt, value, values, parser): - if action == "help": - parser.print_help() - parser.exit() - setattr(values, '_exit', True) - elif action == "version": - parser.print_version() - parser.exit() - setattr(values, '_exit', True) - - else: - return optparse.Option.take_action(self, action, dest, opt, value, values, parser) - - return 1 - -#make_option = Option - class OptionParser(optparse.OptionParser): def exit(self, status=0, msg=None): self.values._exit = True if msg: print msg - # though we must trap and prevent the exit, we also want to end whatever command - # was called def error(self, msg): """error(msg : string) @@ -57,8 +34,6 @@ If you override this in a subclass, it should not return -- it should either exit or raise an exception. """ - #print msg - #print self.format_help() raise def options(option_list):