summaryrefslogtreecommitdiff
path: root/libbe/cmdutil.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2008-11-27 11:03:21 -0500
committerW. Trevor King <wking@drexel.edu>2008-11-27 11:03:21 -0500
commit84551c20fe603ee9832b0b17061660cdf31a913e (patch)
tree20a4e0924b74baee0402213ed9b1dde4214fd840 /libbe/cmdutil.py
parent216e39db0bd3491ee3740f69a8f2afd49f76eb2f (diff)
Added bugid_args option to cmdutil.default_complete.
Now most of the bug-id arguments support Bash completion. Since there will hopefully be lots of bugs in the database, I decided to filter the list of available bugs. Currently, we just auto-complete active bugs for most commands, with the exceptions of open (obviously) and status (which needs to work on all types of bugs).
Diffstat (limited to 'libbe/cmdutil.py')
-rw-r--r--libbe/cmdutil.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index 7f6e5ac..0382664 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -129,17 +129,37 @@ def option_value_pairs(options, parser):
value = getattr(options, option)
yield (option, value)
-def default_complete(options, args, parser):
+def default_complete(options, args, parser, bugid_args={}):
"""
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.
+
+ bugid_args is an optional dict where the keys are positional
+ arguments taking bug shortnames and the values are functions for
+ filtering, since that's a common enough operation.
+ e.g. for "be open [options] BUGID"
+ bugid_args = {0: lambda bug : bug.active == False}
"""
for option,value in option_value_pairs(options, parser):
if value == "--complete":
raise cmdutil.GetCompletions()
- if "--complete" in args:
- raise cmdutil.GetCompletions()
+ for pos,value in enumerate(args):
+ if value == "--complete":
+ if pos in bugid_args:
+ filter = bugid_args[pos]
+ bugshortnames = []
+ try:
+ bd = bugdir.BugDir(from_disk=True,
+ manipulate_encodings=False)
+ bd.load_all_bugs()
+ bugs = [bug for bug in bd if filter(bug) == True]
+ bugshortnames = [bd.bug_shortname(bug) for bug in bugs]
+ except bugdir.NoBugDir:
+ bugshortnames = ["NOBUGDIR"]
+ pass
+ raise GetCompletions(bugshortnames)
+ raise GetCompletions()
def underlined(instring):
"""Produces a version of a string that is underlined with '='