From 84551c20fe603ee9832b0b17061660cdf31a913e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 27 Nov 2008 11:03:21 -0500 Subject: 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). --- libbe/cmdutil.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'libbe') 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 '=' -- cgit