Some small fixes to the help command.
This commit is contained in:
parent
9733a43a16
commit
631020d8a2
2 changed files with 30 additions and 35 deletions
|
|
@ -42,6 +42,10 @@ class CommandMeta(type):
|
||||||
temp.append(lockstring)
|
temp.append(lockstring)
|
||||||
mcs.lock_storage = ";".join(temp)
|
mcs.lock_storage = ";".join(temp)
|
||||||
|
|
||||||
|
if not hasattr(mcs, 'is_exit'):
|
||||||
|
mcs.is_exit = False
|
||||||
|
if not hasattr(mcs, "help_category"):
|
||||||
|
mcs.help_category = "general"
|
||||||
mcs.help_category = mcs.help_category.lower()
|
mcs.help_category = mcs.help_category.lower()
|
||||||
super(CommandMeta, mcs).__init__(*args, **kwargs)
|
super(CommandMeta, mcs).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,10 @@ from src.help.models import HelpEntry
|
||||||
from src.utils import create
|
from src.utils import create
|
||||||
from src.commands.default.muxcommand import MuxCommand
|
from src.commands.default.muxcommand import MuxCommand
|
||||||
|
|
||||||
LIST_ARGS = ["list", "all"]
|
LIST_ARGS = ("list", "all")
|
||||||
SEP = "{C" + "-"*78 + "{n"
|
SEP = "{C" + "-"*78 + "{n"
|
||||||
|
|
||||||
def format_help_entry(title, help_text, aliases=None,
|
def format_help_entry(title, help_text, aliases=None, suggested=None):
|
||||||
suggested=None):
|
|
||||||
"""
|
"""
|
||||||
This visually formats the help entry.
|
This visually formats the help entry.
|
||||||
"""
|
"""
|
||||||
|
|
@ -36,7 +35,9 @@ def format_help_entry(title, help_text, aliases=None,
|
||||||
|
|
||||||
def format_help_list(hdict_cmds, hdict_db):
|
def format_help_list(hdict_cmds, hdict_db):
|
||||||
"""
|
"""
|
||||||
Output a category-ordered list.
|
Output a category-ordered list. The input are the
|
||||||
|
pre-loaded help files for commands and database-helpfiles
|
||||||
|
resectively.
|
||||||
"""
|
"""
|
||||||
string = ""
|
string = ""
|
||||||
if hdict_cmds and hdict_cmds.values():
|
if hdict_cmds and hdict_cmds.values():
|
||||||
|
|
@ -94,21 +95,20 @@ class CmdHelp(Command):
|
||||||
# Listing help entries
|
# Listing help entries
|
||||||
|
|
||||||
if query in LIST_ARGS:
|
if query in LIST_ARGS:
|
||||||
# we want to list all available help entries
|
# we want to list all available help entries, grouped by category.
|
||||||
hdict_cmd = {}
|
hdict_cmd = {}
|
||||||
for cmd in (cmd for cmd in cmdset if cmd.access(caller)
|
for cmd in (cmd for cmd in cmdset if cmd.access(caller)
|
||||||
if not cmd.key.startswith('__')
|
if not cmd.key.startswith('__') and not cmd.is_exit):
|
||||||
and not (hasattr(cmd, 'is_exit') and cmd.is_exit)):
|
try:
|
||||||
if hdict_cmd.has_key(cmd.help_category):
|
|
||||||
hdict_cmd[cmd.help_category].append(cmd.key)
|
hdict_cmd[cmd.help_category].append(cmd.key)
|
||||||
else:
|
except KeyError:
|
||||||
hdict_cmd[cmd.help_category] = [cmd.key]
|
hdict_cmd[cmd.help_category] = [cmd.key]
|
||||||
hdict_db = {}
|
hdict_db = {}
|
||||||
for topic in (topic for topic in HelpEntry.objects.get_all_topics()
|
for topic in (topic for topic in HelpEntry.objects.get_all_topics()
|
||||||
if topic.access(caller, 'view', default=True)):
|
if topic.access(caller, 'view', default=True)):
|
||||||
if hdict_db.has_key(topic.help_category):
|
try:
|
||||||
hdict_db[topic.help_category].append(topic.key)
|
hdict_db[topic.help_category].append(topic.key)
|
||||||
else:
|
except KeyError:
|
||||||
hdict_db[topic.help_category] = [topic.key]
|
hdict_db[topic.help_category] = [topic.key]
|
||||||
help_entry = format_help_list(hdict_cmd, hdict_db)
|
help_entry = format_help_list(hdict_cmd, hdict_db)
|
||||||
caller.msg(help_entry)
|
caller.msg(help_entry)
|
||||||
|
|
@ -117,38 +117,29 @@ class CmdHelp(Command):
|
||||||
# Look for a particular help entry
|
# Look for a particular help entry
|
||||||
|
|
||||||
# Cmd auto-help dynamic entries
|
# Cmd auto-help dynamic entries
|
||||||
cmdmatches = [cmd for cmd in cmdset
|
cmdmatches = [cmd for cmd in cmdset if query in cmd and cmd.access(caller)]
|
||||||
if query in cmd and cmd.access(caller)]
|
|
||||||
if len(cmdmatches) > 1:
|
if len(cmdmatches) > 1:
|
||||||
# multiple matches. Try to limit it down to exact match
|
# multiple matches. Try to limit it down to exact match
|
||||||
exactmatches = [cmd for cmd in cmdmatches if cmd == query]
|
cmdmatches = [cmd for cmd in cmdmatches if cmd == query] or cmdmatches
|
||||||
if exactmatches:
|
|
||||||
cmdmatches = exactmatches
|
|
||||||
|
|
||||||
# Help-database static entries
|
# Help-database static entries
|
||||||
dbmatches = \
|
dbmatches = [topic for topic in
|
||||||
[topic for topic in
|
HelpEntry.objects.find_topicmatch(query, exact=False)
|
||||||
HelpEntry.objects.find_topicmatch(query, exact=False)
|
if topic.access(caller, 'view', default=True)]
|
||||||
if topic.access(caller, 'view', default=True)]
|
|
||||||
if len(dbmatches) > 1:
|
if len(dbmatches) > 1:
|
||||||
exactmatches = \
|
# try to get unique match
|
||||||
[topic for topic in
|
dbmatches = [topic for topic in HelpEntry.objects.find_topicmatch(query, exact=True)
|
||||||
HelpEntry.objects.find_topicmatch(query, exact=True)
|
if topic.access(caller, 'view', default=True)] or dbmatches
|
||||||
if topic.access(caller, 'view', default=True)]
|
|
||||||
if exactmatches:
|
|
||||||
dbmatches = exactmatches
|
|
||||||
|
|
||||||
# Handle result
|
# Handle result
|
||||||
if (not cmdmatches) and (not dbmatches):
|
if (not cmdmatches) and (not dbmatches):
|
||||||
# no normal match. Check if this is a category match instead
|
# no normal match. Check if this is a category match instead
|
||||||
categ_cmdmatches = [cmd.key for cmd in cmdset
|
categ_cmdmatches = [cmd.key for cmd in cmdset if query == cmd.help_category and cmd.access(caller)]
|
||||||
if query == cmd.help_category and cmd.access(caller)]
|
categ_dbmatches = [topic.key for topic in HelpEntry.objects.find_topics_with_category(query)
|
||||||
categ_dbmatches = \
|
if topic.access(caller, 'view', default=True)]
|
||||||
[topic.key for topic in
|
|
||||||
HelpEntry.objects.find_topics_with_category(query)
|
|
||||||
if topic.access(caller, 'view', default=True)]
|
|
||||||
cmddict = None
|
cmddict = None
|
||||||
dbdict = None
|
dbdict = None
|
||||||
|
|
||||||
if categ_cmdmatches:
|
if categ_cmdmatches:
|
||||||
cmddict = {query:categ_cmdmatches}
|
cmddict = {query:categ_cmdmatches}
|
||||||
if categ_dbmatches:
|
if categ_dbmatches:
|
||||||
|
|
@ -159,7 +150,7 @@ class CmdHelp(Command):
|
||||||
help_entry = "No help entry found for '%s'" % self.original_args
|
help_entry = "No help entry found for '%s'" % self.original_args
|
||||||
|
|
||||||
elif len(cmdmatches) == 1:
|
elif len(cmdmatches) == 1:
|
||||||
# we matched against a command name or alias. Show its help entry.
|
# we matched against a unique command name or alias. Show its help entry.
|
||||||
suggested = []
|
suggested = []
|
||||||
if dbmatches:
|
if dbmatches:
|
||||||
suggested = [entry.key for entry in dbmatches]
|
suggested = [entry.key for entry in dbmatches]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue