Added auto_help as a class property on Commands. This allows to turn on/off auto-help generation on a per-command basis (default is on).
This commit is contained in:
parent
6a78fdafcb
commit
aae67225a4
2 changed files with 12 additions and 6 deletions
|
|
@ -47,7 +47,8 @@ class CommandMeta(type):
|
||||||
mcs.arg_regex = re.compile(r"%s" % mcs.arg_regex, re.I)
|
mcs.arg_regex = re.compile(r"%s" % mcs.arg_regex, re.I)
|
||||||
else:
|
else:
|
||||||
mcs.arg_regex = None
|
mcs.arg_regex = None
|
||||||
|
if not hasattr(mcs, "auto_help"):
|
||||||
|
mcs.auto_help = True
|
||||||
if not hasattr(mcs, 'is_exit'):
|
if not hasattr(mcs, 'is_exit'):
|
||||||
mcs.is_exit = False
|
mcs.is_exit = False
|
||||||
if not hasattr(mcs, "help_category"):
|
if not hasattr(mcs, "help_category"):
|
||||||
|
|
@ -99,11 +100,16 @@ class Command(object):
|
||||||
locks = ""
|
locks = ""
|
||||||
# used by the help system to group commands in lists.
|
# used by the help system to group commands in lists.
|
||||||
help_category = "general"
|
help_category = "general"
|
||||||
|
|
||||||
|
# this normally does not need to be changed. It allows to turn off
|
||||||
|
# auto-help entry creation for individual commands.
|
||||||
|
auto_help = True
|
||||||
# There is also the property 'obj'. This gets set by the system
|
# There is also the property 'obj'. This gets set by the system
|
||||||
# on the fly to tie this particular command to a certain in-game entity.
|
# on the fly to tie this particular command to a certain in-game entity.
|
||||||
# self.obj should NOT be defined here since it will not be overwritten
|
# self.obj should NOT be defined here since it will not be overwritten
|
||||||
# if it already exists.
|
# if it already exists.
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lockhandler = LockHandler(self)
|
self.lockhandler = LockHandler(self)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,13 +92,13 @@ class CmdHelp(Command):
|
||||||
# having to allow doublet commands to manage exits etc.
|
# having to allow doublet commands to manage exits etc.
|
||||||
cmdset.make_unique(caller)
|
cmdset.make_unique(caller)
|
||||||
|
|
||||||
# Listing help entries
|
# Listing all help entries
|
||||||
|
|
||||||
if query in LIST_ARGS:
|
if query in LIST_ARGS:
|
||||||
# we want to list all available help entries, grouped by category.
|
# 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.auto_help and not cmd.is_exit
|
||||||
if not cmd.key.startswith('__') and not cmd.is_exit):
|
and not cmd.key.startswith('__') and cmd.access(caller)):
|
||||||
try:
|
try:
|
||||||
hdict_cmd[cmd.help_category].append(cmd.key)
|
hdict_cmd[cmd.help_category].append(cmd.key)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
@ -117,7 +117,7 @@ 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 if query in cmd and cmd.access(caller)]
|
cmdmatches = [cmd for cmd in cmdset if query in cmd and cmd.auto_help 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
|
||||||
cmdmatches = [cmd for cmd in cmdmatches if cmd == query] or cmdmatches
|
cmdmatches = [cmd for cmd in cmdmatches if cmd == query] or cmdmatches
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue