diff options
author | W. Trevor King <wking@drexel.edu> | 2009-07-13 07:23:16 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-07-13 07:23:16 -0400 |
commit | ffb8e95faed6fec4e1b06d7bfba3cc21661c677f (patch) | |
tree | 162d51088197c8b59848d3fbea72dd70e2424a36 /libbe | |
parent | 77fe8d1e2c71fb783160ab9946d9dc9e471a11c1 (diff) | |
download | bugseverywhere-ffb8e95faed6fec4e1b06d7bfba3cc21661c677f.tar.gz |
Use CmdOptionParser in "be".
All the becommands have been using cmdutil CmdOptionParser for a long
time, but "be" parsed its options by hand. Now it used
CmdOptionParser, which makes adding new options much easier.
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/cmdutil.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index 0bee9db..a91b1c7 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -75,7 +75,7 @@ def execute(cmd, args): cmd.execute([a.decode(enc) for a in args]) return 0 -def help(cmd=None): +def help(cmd=None, parser=None): if cmd != None: return get_command(cmd).help() else: @@ -84,17 +84,15 @@ def help(cmd=None): cmdlist.append((name, module.__desc__)) longest_cmd_len = max([len(name) for name,desc in cmdlist]) ret = ["Bugs Everywhere - Distributed bug tracking", - "", - "usage: be [command] [command_options ...] [command_args ...]", - "or: be help", - "or: be help [command]", - "", - "Supported commands"] + "", "Supported commands"] for name, desc in cmdlist: numExtraSpaces = longest_cmd_len-len(name) ret.append("be %s%*s %s" % (name, numExtraSpaces, "", desc)) - - return "\n".join(ret) + ret.extend(["", "Run", " be help [command]", "for more information."]) + longhelp = "\n".join(ret) + if parser == None: + return longhelp + return parser.help_str() + "\n" + longhelp def completions(cmd): parser = get_command(cmd).get_parser() @@ -108,6 +106,13 @@ def raise_get_help(option, opt, value, parser): def raise_get_completions(option, opt, value, parser): print "got completion arg" + if hasattr(parser, "command") and parser.command == "be": + comps = [] + for command, module in iter_commands(): + comps.append(command) + for opt in parser.option_list: + comps.append(opt.get_opt_string()) + raise GetCompletions(comps) raise GetCompletions(completions(sys.argv[1])) class CmdOptionParser(optparse.OptionParser): |