Changed @help to @syntax, @morehelp to @help, and changed the output of @morehelp to be prettier.

This commit is contained in:
Jeremy Fincher 2003-09-25 08:14:46 +00:00
parent 6061513c20
commit c3e9c38b6a
2 changed files with 35 additions and 37 deletions

View File

@ -36,6 +36,7 @@ Miscellaneous commands.
from fix import * from fix import *
import os import os
import sys
import time import time
import getopt import getopt
import pprint import pprint
@ -114,10 +115,10 @@ class MiscCommands(callbacks.Privmsg):
irc.error(msg, 'There is no plugin named %s, ' \ irc.error(msg, 'There is no plugin named %s, ' \
'or that plugin has no commands.' % name) 'or that plugin has no commands.' % name)
def help(self, irc, msg, args): def syntax(self, irc, msg, args):
"""<command> """<command>
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. 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. 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: if hasattr(method, '__doc__') and method.__doc__ is not None:
doclines = method.__doc__.strip().splitlines() doclines = method.__doc__.strip().splitlines()
help = doclines.pop(0) help = doclines.pop(0)
if doclines: irc.reply(msg, '%s %s' % (command, help))
s = '%s %s (for more help use the morehelp command)'
else:
s = '%s %s'
irc.reply(msg, s % (command, help))
else: else:
irc.reply(msg, 'That command exists, but has no help.') irc.reply(msg, 'That command exists, '
'but has no syntax description.')
else: else:
cb = irc.getCallback(command) cb = irc.getCallback(command)
if cb: if cb:
s = ''
if hasattr(cb, '__doc__') and cb.__doc__ is not None: if hasattr(cb, '__doc__') and cb.__doc__ is not None:
doclines = cb.__doc__.strip().splitlines() s = cb.__doc__
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: else:
module = __import__(cb.__module__) module = sys.modules[cb.__module__]
if hasattr(module, '__doc__') and module.__doc__: if hasattr(module, '__doc__') and module.__doc__:
doclines = module.__doc__.strip().splitlines() s = module.__doc__
help = ' '.join(map(str.strip, doclines)) if s:
if not help.endswith('.'): s = ' '.join(map(str.strip, s.splitlines()))
help += '.' if not s.endswith('.'):
help += ' Use the list command to see what ' \ s += '.'
'commands this plugin supports.' s += ' Use the list command to see what commands this ' \
irc.reply(msg, help) 'plugin supports.'
else: else:
irc.error(msg, 'That plugin has no help.') s = 'That plugin has no help description.'
irc.reply(msg, s)
else: else:
irc.error(msg, 'There is no such command or plugin.') irc.error(msg, 'There is no such command or plugin.')
def morehelp(self, irc, msg, args): def help(self, irc, msg, args):
"""<command> """<command>
This command gives more help than is provided by the simple argument This command gives a much more useful description than the simple
list given by the command 'help'. argument list given by the command 'syntax'.
""" """
command = callbacks.canonicalName(privmsgs.getArgs(args)) command = callbacks.canonicalName(privmsgs.getArgs(args))
cb = irc.findCallback(command) cb = irc.findCallback(command)
@ -177,17 +171,19 @@ class MiscCommands(callbacks.Privmsg):
if hasattr(method, '__doc__') and method.__doc__ is not None: if hasattr(method, '__doc__') and method.__doc__ is not None:
doclines = method.__doc__.splitlines() doclines = method.__doc__.splitlines()
simplehelp = doclines.pop(0) simplehelp = doclines.pop(0)
simplehelp = '(%s %s)' % (command, simplehelp)
if doclines: if doclines:
doclines = filter(None, doclines) doclines = filter(None, doclines)
doclines = map(str.strip, doclines) doclines = map(str.strip, doclines)
help = ' '.join(doclines) help = ' '.join(doclines)
irc.reply(msg, help) s = '%s %s' % (ircutils.bold(simplehelp),help)
irc.reply(msg, s)
else: else:
irc.reply(msg, 'That command has no more help. '\ irc.reply(msg, 'That command has no help. '\
'The original help is this: %s %s' % \ 'The syntax is this: %s %s' % \
(command, simplehelp)) (command, simplehelp))
else: else:
irc.error(msg, 'That command has no help at all.') irc.error(msg, '%s has no help or syntax description.'%command)
else: else:
irc.error(msg, 'There is no such command %s.' % command) irc.error(msg, 'There is no such command %s.' % command)

View File

@ -60,13 +60,15 @@ class MiscCommandsTestCase(ChannelPluginTestCase, PluginDocumentation):
finally: finally:
conf.repylWhenNotCommand = False conf.repylWhenNotCommand = False
def testSyntax(self):
self.assertNotError('syntax list')
self.assertNotError('syntax help')
def testHelp(self): def testHelp(self):
self.assertNotError('help list') self.assertNotError('help list')
self.assertNotError('help help') self.assertNotError('help syntax')
self.assertRegexp('help help', r'^\x02\(help')
def testMorehelp(self): self.assertError('help morehelp')
self.assertNotError('morehelp list')
self.assertNotError('morehelp morehelp')
def testList(self): def testList(self):
self.assertNotError('list MiscCommands') self.assertNotError('list MiscCommands')