From 7643e6b33715c199ed6106fb9bc1e10685deb0a6 Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Tue, 1 Dec 2009 23:54:18 +0100 Subject: [PATCH] Better 'help' command for long documentation If you type 'help', you get the list of commands with the first line of the docstring, if you type 'help cmd' you get the complete docstring. --- jabberbot.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/jabberbot.py b/jabberbot.py index 7d9f63f..80f30c4 100644 --- a/jabberbot.py +++ b/jabberbot.py @@ -368,14 +368,24 @@ class JabberBot(object): return "" @botcmd - def help( self, mess, args): - """Returns a help string listing available options. Automatically assigned to the "help" command.""" - usage = '\n'.join(sorted(['%s: %s' % (name, command.__doc__ or '(undocumented)') for (name, command) in self.commands.items() if name != 'help' and not command._jabberbot_hidden])) + def help(self, mess, args): + """Returns a help string listing available options. - if self.__doc__: - description = self.__doc__.strip() + Automatically assigned to the "help" command.""" + if not args: + if self.__doc__: + description = self.__doc__.strip() + else: + description = 'Available commands:' + + usage = '\n'.join(sorted(['%s: %s' % (name, (command.__doc__ or '(undocumented)').split('\n', 1)[0]) for (name, command) in self.commands.items() if name != 'help' and not command._jabberbot_hidden])) + usage = usage + '\n\nType help to get more info about that specific command.' else: - description = 'Available commands:' + description = '' + if args in self.commands: + usage = self.commands[args].__doc__ or 'undocumented' + else: + usage = 'That command is not defined.' top = self.top_of_help_message() bottom = self.bottom_of_help_message() -- 2.11.4.GIT