aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2008-11-27 10:16:18 -0500
committerW. Trevor King <wking@drexel.edu>2008-11-27 10:16:18 -0500
commit216e39db0bd3491ee3740f69a8f2afd49f76eb2f (patch)
tree5fc519ba693a4819f725de6e5b4d3de6fea1deb8 /libbe
parent8e989347bdefab6a77e32072265fa0bd8c143c43 (diff)
downloadbugseverywhere-216e39db0bd3491ee3740f69a8f2afd49f76eb2f.tar.gz
Command completion simplified and working for list, dummies for other cmds.
All the other commands currently use default_complete(), which has no effect other than catching the --complete option and effectively aborting execution. This closes 8e1bbda4-35b6-4579-849d-117b1596ee99
Diffstat (limited to 'libbe')
-rw-r--r--libbe/cmdutil.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index 2bfe6d4..7f6e5ac 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -86,7 +86,7 @@ def help(cmd=None):
ret.append("be %s%*s %s" % (name, numExtraSpaces, "", desc))
return "\n".join(ret)
-def options(cmd):
+def completions(cmd):
parser = get_command(cmd).get_parser()
longopts = []
for opt in parser.option_list:
@@ -97,7 +97,7 @@ def raise_get_help(option, opt, value, parser):
raise GetHelp
def raise_get_completions(option, opt, value, parser):
- raise GetCompletions(options(sys.argv[1]))
+ raise GetCompletions(completions(sys.argv[1]))
class CmdOptionParser(optparse.OptionParser):
def __init__(self, usage):
@@ -121,6 +121,26 @@ class CmdOptionParser(optparse.OptionParser):
self.print_help(f)
return f.getvalue()
+def option_value_pairs(options, parser):
+ """
+ Iterate through OptionParser (option, value) pairs.
+ """
+ for option in [o.dest for o in parser.option_list if o.dest != None]:
+ value = getattr(options, option)
+ yield (option, value)
+
+def default_complete(options, args, parser):
+ """
+ A dud complete implementation for becommands to that the
+ --complete argument doesn't cause any problems. Use this
+ until you've set up a command-specific complete function.
+ """
+ for option,value in option_value_pairs(options, parser):
+ if value == "--complete":
+ raise cmdutil.GetCompletions()
+ if "--complete" in args:
+ raise cmdutil.GetCompletions()
+
def underlined(instring):
"""Produces a version of a string that is underlined with '='