Further cleanup in the error logic for commands - the system now gives resonable suggestions for all commands.
This commit is contained in:
parent
181abb84a8
commit
e4006bf386
3 changed files with 10 additions and 6 deletions
|
|
@ -193,7 +193,7 @@ def cmdhandler(caller, raw_string, testing=False):
|
||||||
sysarg = raw_string
|
sysarg = raw_string
|
||||||
else:
|
else:
|
||||||
sysarg = "Command '%s' is not available." % raw_string
|
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:
|
if suggestions:
|
||||||
sysarg += " Did you maybe mean %s?" % utils.list_to_string(suggestions, 'or', addquote=True)
|
sysarg += " Did you maybe mean %s?" % utils.list_to_string(suggestions, 'or', addquote=True)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -383,11 +383,16 @@ class CmdSet(object):
|
||||||
"""
|
"""
|
||||||
pass
|
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
|
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 = []
|
||||||
[names.extend(cmd.aliases) for cmd in self.commands]
|
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
|
return names
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,6 @@ class CmdHelp(Command):
|
||||||
if not suggestions:
|
if not suggestions:
|
||||||
suggestions = [sugg for sugg in vocabulary if sugg != query and sugg.startswith(query)]
|
suggestions = [sugg for sugg in vocabulary if sugg != query and sugg.startswith(query)]
|
||||||
|
|
||||||
|
|
||||||
# try an exact command auto-help match
|
# try an exact command auto-help match
|
||||||
match = [cmd for cmd in all_cmds if cmd == query]
|
match = [cmd for cmd in all_cmds if cmd == query]
|
||||||
if len(match) == 1:
|
if len(match) == 1:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue