From aae67225a49ac339e26422d6647350420d4bb48a Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 13 Mar 2012 22:07:51 +0100 Subject: [PATCH] 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). --- src/commands/command.py | 10 ++++++++-- src/commands/default/help.py | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/commands/command.py b/src/commands/command.py index f4ede9492a..c7908176d3 100644 --- a/src/commands/command.py +++ b/src/commands/command.py @@ -47,9 +47,10 @@ class CommandMeta(type): mcs.arg_regex = re.compile(r"%s" % mcs.arg_regex, re.I) else: mcs.arg_regex = None - + if not hasattr(mcs, "auto_help"): + mcs.auto_help = True if not hasattr(mcs, 'is_exit'): - mcs.is_exit = False + mcs.is_exit = False if not hasattr(mcs, "help_category"): mcs.help_category = "general" mcs.help_category = mcs.help_category.lower() @@ -99,10 +100,15 @@ class Command(object): locks = "" # used by the help system to group commands in lists. 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 # 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 # if it already exists. + def __init__(self): self.lockhandler = LockHandler(self) diff --git a/src/commands/default/help.py b/src/commands/default/help.py index 5bb4106b5c..91ce86f163 100644 --- a/src/commands/default/help.py +++ b/src/commands/default/help.py @@ -92,13 +92,13 @@ class CmdHelp(Command): # having to allow doublet commands to manage exits etc. cmdset.make_unique(caller) - # Listing help entries + # Listing all help entries if query in LIST_ARGS: # we want to list all available help entries, grouped by category. hdict_cmd = {} - for cmd in (cmd for cmd in cmdset if cmd.access(caller) - if not cmd.key.startswith('__') and not cmd.is_exit): + for cmd in (cmd for cmd in cmdset if cmd.auto_help and not cmd.is_exit + and not cmd.key.startswith('__') and cmd.access(caller)): try: hdict_cmd[cmd.help_category].append(cmd.key) except KeyError: @@ -117,7 +117,7 @@ class CmdHelp(Command): # Look for a particular help entry # 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: # multiple matches. Try to limit it down to exact match cmdmatches = [cmd for cmd in cmdmatches if cmd == query] or cmdmatches