Further cleanup in the error logic for commands - the system now gives resonable suggestions for all commands.

This commit is contained in:
Griatch 2012-04-22 20:04:24 +02:00
parent 181abb84a8
commit e4006bf386
3 changed files with 10 additions and 6 deletions

View file

@ -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:

View file

@ -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

View file

@ -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: