diff options
author | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-03-22 14:45:11 +0000 |
---|---|---|
committer | Aaron Bentley <abentley@panoramicfeedback.com> | 2005-03-22 14:45:11 +0000 |
commit | e30304e9b3ba176dbbd9710d561d81aa4670c454 (patch) | |
tree | 6e9c5add254037bec694ec5bfbfc1852313d0c2e /libbe/cmdutil.py | |
parent | 9bfac949bf3764f61a42633b88e54ce766d95786 (diff) | |
download | bugseverywhere-e30304e9b3ba176dbbd9710d561d81aa4670c454.tar.gz |
Pulled in Fai's optparser
Diffstat (limited to 'libbe/cmdutil.py')
-rw-r--r-- | libbe/cmdutil.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index 86fee80..e6d5a8f 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -1,6 +1,7 @@ import bugdir import plugin import os +import optparse def unique_name(bug, bugs): chars = 1 @@ -80,9 +81,37 @@ def get_command(command_name): def execute(cmd, args): return get_command(cmd).execute(args) -def help(cmd, args): +def help(cmd): return get_command(cmd).help() + +class GetHelp(Exception): + pass + + +class UsageError(Exception): + pass + + +def raise_get_help(option, opt, value, parser): + raise GetHelp + + +class CmdOptionParser(optparse.OptionParser): + def __init__(self, usage): + optparse.OptionParser.__init__(self, usage) + self.remove_option("-h") + self.add_option("-h", "--help", action="callback", + callback=raise_get_help, help="Print a help message") + + def error(self, message): + raise UsageError(message) + + def iter_options(self): + return iter_combine([self._short_opt.iterkeys(), + self._long_opt.iterkeys()]) + + def underlined(instring): """Produces a version of a string that is underlined with '=' |