From e4006bf386182e6517c39009fcba30589e7c9c84 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 22 Apr 2012 20:04:24 +0200 Subject: [PATCH] Further cleanup in the error logic for commands - the system now gives resonable suggestions for all commands. --- src/commands/cmdhandler.py | 2 +- src/commands/cmdset.py | 13 +++++++++---- src/commands/default/help.py | 1 - 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index 0c6c4df232..a0c8739485 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -193,7 +193,7 @@ def cmdhandler(caller, raw_string, testing=False): sysarg = raw_string else: sysarg = "Command '%s' is not available." % raw_string - suggestions = string_suggestions(raw_string, cmdset.get_all_cmd_keys_and_aliases(), cutoff=0.7, maxnum=3) + suggestions = string_suggestions(raw_string, cmdset.get_all_cmd_keys_and_aliases(caller), cutoff=0.7, maxnum=3) if suggestions: sysarg += " Did you maybe mean %s?" % utils.list_to_string(suggestions, 'or', addquote=True) else: diff --git a/src/commands/cmdset.py b/src/commands/cmdset.py index b7efe313e6..944d0213bc 100644 --- a/src/commands/cmdset.py +++ b/src/commands/cmdset.py @@ -383,11 +383,16 @@ class CmdSet(object): """ pass - def get_all_cmd_keys_and_aliases(self): + def get_all_cmd_keys_and_aliases(self, caller=None): """ Returns a list of all command keys and aliases - available in this cmdset. + available in this cmdset. If caller is given, the + comands is checked for access on the "call" type + before being returned. """ - names = [cmd.key for cmd in self.commands] - [names.extend(cmd.aliases) for cmd in self.commands] + names = [] + if caller: + [names.extend([cmd.key] + cmd.aliases) for cmd in self.commands if cmd.access(caller)] + else: + [names.extend([cmd.key] + cmd.aliases) for cmd in self.commands] return names diff --git a/src/commands/default/help.py b/src/commands/default/help.py index 310079297e..932a6adc67 100644 --- a/src/commands/default/help.py +++ b/src/commands/default/help.py @@ -126,7 +126,6 @@ class CmdHelp(Command): if not suggestions: suggestions = [sugg for sugg in vocabulary if sugg != query and sugg.startswith(query)] - # try an exact command auto-help match match = [cmd for cmd in all_cmds if cmd == query] if len(match) == 1: