From c3e9c38b6ae6945e92b4d35e5b518d5fda6f4616 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 25 Sep 2003 08:14:46 +0000 Subject: [PATCH] Changed @help to @syntax, @morehelp to @help, and changed the output of @morehelp to be prettier. --- src/MiscCommands.py | 60 ++++++++++++++++++--------------------- test/test_MiscCommands.py | 12 ++++---- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/MiscCommands.py b/src/MiscCommands.py index 928d02a30..0c29e9254 100755 --- a/src/MiscCommands.py +++ b/src/MiscCommands.py @@ -36,6 +36,7 @@ Miscellaneous commands. from fix import * import os +import sys import time import getopt import pprint @@ -114,10 +115,10 @@ class MiscCommands(callbacks.Privmsg): irc.error(msg, 'There is no plugin named %s, ' \ 'or that plugin has no commands.' % name) - def help(self, irc, msg, args): + def syntax(self, irc, msg, args): """ - Gives the help for a specific command. To find commands, + Gives the syntax for a specific command. To find commands, use the 'list' command to go see the commands offered by a plugin. The 'list' command by itself will show you what plugins have commands. """ @@ -131,44 +132,37 @@ class MiscCommands(callbacks.Privmsg): if hasattr(method, '__doc__') and method.__doc__ is not None: doclines = method.__doc__.strip().splitlines() help = doclines.pop(0) - if doclines: - s = '%s %s (for more help use the morehelp command)' - else: - s = '%s %s' - irc.reply(msg, s % (command, help)) + irc.reply(msg, '%s %s' % (command, help)) else: - irc.reply(msg, 'That command exists, but has no help.') + irc.reply(msg, 'That command exists, ' + 'but has no syntax description.') else: cb = irc.getCallback(command) if cb: + s = '' if hasattr(cb, '__doc__') and cb.__doc__ is not None: - doclines = cb.__doc__.strip().splitlines() - help = ' '.join(map(str.strip, doclines)) - if not help.endswith('.'): - help += '.' - help += ' Use the list command to see what commands ' \ - 'this plugin supports.' - irc.reply(msg, help) + s = cb.__doc__ else: - module = __import__(cb.__module__) + module = sys.modules[cb.__module__] if hasattr(module, '__doc__') and module.__doc__: - doclines = module.__doc__.strip().splitlines() - help = ' '.join(map(str.strip, doclines)) - if not help.endswith('.'): - help += '.' - help += ' Use the list command to see what ' \ - 'commands this plugin supports.' - irc.reply(msg, help) - else: - irc.error(msg, 'That plugin has no help.') + s = module.__doc__ + if s: + s = ' '.join(map(str.strip, s.splitlines())) + if not s.endswith('.'): + s += '.' + s += ' Use the list command to see what commands this ' \ + 'plugin supports.' + else: + s = 'That plugin has no help description.' + irc.reply(msg, s) else: irc.error(msg, 'There is no such command or plugin.') - def morehelp(self, irc, msg, args): + def help(self, irc, msg, args): """ - This command gives more help than is provided by the simple argument - list given by the command 'help'. + This command gives a much more useful description than the simple + argument list given by the command 'syntax'. """ command = callbacks.canonicalName(privmsgs.getArgs(args)) cb = irc.findCallback(command) @@ -177,17 +171,19 @@ class MiscCommands(callbacks.Privmsg): if hasattr(method, '__doc__') and method.__doc__ is not None: doclines = method.__doc__.splitlines() simplehelp = doclines.pop(0) + simplehelp = '(%s %s)' % (command, simplehelp) if doclines: doclines = filter(None, doclines) doclines = map(str.strip, doclines) help = ' '.join(doclines) - irc.reply(msg, help) + s = '%s %s' % (ircutils.bold(simplehelp),help) + irc.reply(msg, s) else: - irc.reply(msg, 'That command has no more help. '\ - 'The original help is this: %s %s' % \ + irc.reply(msg, 'That command has no help. '\ + 'The syntax is this: %s %s' % \ (command, simplehelp)) else: - irc.error(msg, 'That command has no help at all.') + irc.error(msg, '%s has no help or syntax description.'%command) else: irc.error(msg, 'There is no such command %s.' % command) diff --git a/test/test_MiscCommands.py b/test/test_MiscCommands.py index 8d7462cb3..8a0378b9a 100644 --- a/test/test_MiscCommands.py +++ b/test/test_MiscCommands.py @@ -60,13 +60,15 @@ class MiscCommandsTestCase(ChannelPluginTestCase, PluginDocumentation): finally: conf.repylWhenNotCommand = False + def testSyntax(self): + self.assertNotError('syntax list') + self.assertNotError('syntax help') + def testHelp(self): self.assertNotError('help list') - self.assertNotError('help help') - - def testMorehelp(self): - self.assertNotError('morehelp list') - self.assertNotError('morehelp morehelp') + self.assertNotError('help syntax') + self.assertRegexp('help help', r'^\x02\(help') + self.assertError('help morehelp') def testList(self): self.assertNotError('list MiscCommands')