Fixed some strange behaviour in the help system due to recent changes in how cmdsets are merged by cmdhandler.
This commit is contained in:
parent
e767b3458a
commit
9be2b5a64b
3 changed files with 49 additions and 16 deletions
|
|
@ -17,7 +17,9 @@ LIST_ARGS = ["list", "all"]
|
||||||
|
|
||||||
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.
|
||||||
|
"""
|
||||||
string = "-"*70 + "\n"
|
string = "-"*70 + "\n"
|
||||||
if title:
|
if title:
|
||||||
string += "Help topic for {w%s{n" % (title.capitalize())
|
string += "Help topic for {w%s{n" % (title.capitalize())
|
||||||
|
|
@ -33,13 +35,17 @@ def format_help_entry(title, help_text, aliases=None,
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def format_help_list(hdict_cmds, hdict_db):
|
def format_help_list(hdict_cmds, hdict_db):
|
||||||
"Output a category-ordered list"
|
"""
|
||||||
string = "\n\r" + "-"*70 + "\n\r {gCommand help entries{n\n" + "-"*70
|
Output a category-ordered list.
|
||||||
for category in sorted(hdict_cmds.keys()):
|
"""
|
||||||
string += "\n {w%s{n:\n" % \
|
string = ""
|
||||||
(str(category).capitalize())
|
if hdict_cmds and hdict_cmds.values():
|
||||||
string += fill(", ".join(sorted(hdict_cmds[category])))
|
string += "\n\r" + "-"*70 + "\n\r {gCommand help entries{n\n" + "-"*70
|
||||||
if hdict_db:
|
for category in sorted(hdict_cmds.keys()):
|
||||||
|
string += "\n {w%s{n:\n" % \
|
||||||
|
(str(category).capitalize())
|
||||||
|
string += fill(", ".join(sorted(hdict_cmds[category])))
|
||||||
|
if hdict_db and hdict_db.values():
|
||||||
string += "\n\r\n\r" + "-"*70 + "\n\r {gOther help entries{n\n" + '-'*70
|
string += "\n\r\n\r" + "-"*70 + "\n\r {gOther help entries{n\n" + '-'*70
|
||||||
for category in sorted(hdict_db.keys()):
|
for category in sorted(hdict_db.keys()):
|
||||||
string += "\n\r {w%s{n:\n" % (str(category).capitalize())
|
string += "\n\r {w%s{n:\n" % (str(category).capitalize())
|
||||||
|
|
@ -79,6 +85,10 @@ class CmdHelp(Command):
|
||||||
if not query:
|
if not query:
|
||||||
query = "all"
|
query = "all"
|
||||||
|
|
||||||
|
# removing doublets in cmdset, caused by cmdhandler
|
||||||
|
# having to allow doublet commands to manage exits etc.
|
||||||
|
cmdset.make_unique(caller)
|
||||||
|
|
||||||
# Listing help entries
|
# Listing help entries
|
||||||
|
|
||||||
if query in LIST_ARGS:
|
if query in LIST_ARGS:
|
||||||
|
|
@ -129,15 +139,20 @@ class CmdHelp(Command):
|
||||||
# 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 for cmd in cmdset
|
categ_cmdmatches = [cmd.key for cmd in cmdset
|
||||||
if query == cmd.help_category and has_perm(caller, cmd, 'cmd')]
|
if query == cmd.help_category and has_perm(caller, cmd, 'cmd')]
|
||||||
categ_dbmatches = \
|
categ_dbmatches = \
|
||||||
[topic for topic in
|
[topic.key for topic in
|
||||||
HelpEntry.objects.find_topics_with_category(query)
|
HelpEntry.objects.find_topics_with_category(query)
|
||||||
if has_perm(caller, topic, 'view')]
|
if has_perm(caller, topic, 'view')]
|
||||||
if categ_cmdmatches or categ_dbmatches:
|
cmddict = None
|
||||||
help_entry = format_help_list({query:categ_cmdmatches},
|
dbdict = None
|
||||||
{query:categ_dbmatches})
|
if categ_cmdmatches:
|
||||||
|
cmddict = {query:categ_cmdmatches}
|
||||||
|
if categ_dbmatches:
|
||||||
|
dbdict = {query:categ_dbmatches}
|
||||||
|
if cmddict or dbdict:
|
||||||
|
help_entry = format_help_list(cmddict, dbdict)
|
||||||
else:
|
else:
|
||||||
help_entry = "No help entry found for '%s'" % query
|
help_entry = "No help entry found for '%s'" % query
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,6 @@ caller.msg("A %s was created." % red_button.key)
|
||||||
# again (so as to avoid duplicate objects when testing the script many
|
# again (so as to avoid duplicate objects when testing the script many
|
||||||
# times).
|
# times).
|
||||||
|
|
||||||
caller.msg(limbo.key)
|
|
||||||
|
|
||||||
# the python variables we assign to must match the ones given in the
|
# the python variables we assign to must match the ones given in the
|
||||||
# header for the system to be able to delete them afterwards during a
|
# header for the system to be able to delete them afterwards during a
|
||||||
# debugging run.
|
# debugging run.
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,26 @@ class CmdSet(object):
|
||||||
cmdset.key_mergetypes = copy.deepcopy(self.key_mergetypes)
|
cmdset.key_mergetypes = copy.deepcopy(self.key_mergetypes)
|
||||||
return cmdset
|
return cmdset
|
||||||
|
|
||||||
|
def make_unique(self, caller):
|
||||||
|
"""
|
||||||
|
This is an unsafe command meant to clean out a cmdset of
|
||||||
|
doublet commands after it has been created. It is useful
|
||||||
|
for commands inheriting cmdsets from the cmdhandler where
|
||||||
|
obj-based cmdsets always are added double. Doublets will
|
||||||
|
be weeded out with preference to commands defined on caller,
|
||||||
|
otherwise just by first-come-first-served.
|
||||||
|
"""
|
||||||
|
unique = {}
|
||||||
|
for cmd in self.commands:
|
||||||
|
if cmd.key in unique:
|
||||||
|
ocmd = unique[cmd.key]
|
||||||
|
if (hasattr(cmd, 'obj') and cmd.obj == caller) and not \
|
||||||
|
(hasattr(ocmd, 'obj') and ocmd.obj == caller):
|
||||||
|
unique[cmd.key] = cmd
|
||||||
|
else:
|
||||||
|
unique[cmd.key] = cmd
|
||||||
|
self.commands = unique.values()
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue