fix docstring for Plugin.plugin command so it actually says what the command will do.

also add a Plugin.plugins command, which always returns a list of all plugins containing a command.
add a test for it.
This commit is contained in:
Daniel Folkinshteyn 2010-04-21 16:38:25 -04:00 committed by Valentin Lorentz
parent 92fc1e308f
commit 7505f839fc
2 changed files with 43 additions and 3 deletions

View File

@ -72,7 +72,10 @@ class Plugin(callbacks.Plugin):
def plugin(self, irc, msg, args, command): def plugin(self, irc, msg, args, command):
"""<command> """<command>
Returns the plugin(s) that <command> is in. Returns the name of the plugin that would be used to call <command>.
If it is not uniquely determined, returns list of all plugins that
contain <command>.
""" """
(maxL, cbs) = irc.findCallbacksForArgs(command) (maxL, cbs) = irc.findCallbacksForArgs(command)
L = [] L = []
@ -94,7 +97,40 @@ class Plugin(callbacks.Plugin):
irc.error(format(_('There is no command %q.'), command)) irc.error(format(_('There is no command %q.'), command))
plugin = wrap(plugin, [many('something')]) plugin = wrap(plugin, [many('something')])
def _findCallbacks(self, irc, command):
command = map(callbacks.canonicalName, command)
plugin_list = []
for cb in irc.callbacks:
if not hasattr(cb, 'getCommand'):
continue
commandlist = cb.getCommand(command)
if commandlist:
plugin_list.append(cb.name())
return plugin_list
@internationalizeDocstring @internationalizeDocstring
def plugins(self, irc, msg, args, command):
"""<command>
Returns the names of all plugins that contain <command>.
"""
L = self._findCallbacks(irc, command)
command = callbacks.formatCommand(command)
if L:
if irc.nested:
irc.reply(format('%L', L))
else:
if len(L) > 1:
plugin = 'plugins'
else:
plugin = 'plugin'
irc.reply(format('The %q command is available in the %L %s.',
command, L, plugin))
else:
irc.error(format('There is no command %q.', command))
plugins = wrap(plugins, [many('something')])
>>>>>>> 3005752... fix docstring for Plugin.plugin command so it actually says what the command will do.
def author(self, irc, msg, args, cb): def author(self, irc, msg, args, cb):
"""<plugin> """<plugin>

View File

@ -30,11 +30,15 @@
from supybot.test import * from supybot.test import *
class PluginTestCase(PluginTestCase): class PluginTestCase(PluginTestCase):
plugins = ('Plugin', 'Utilities') plugins = ('Plugin', 'Utilities', 'Admin', 'Format')
def testPlugin(self): def testPlugin(self):
self.assertRegexp('plugin plugin', 'available.*Plugin plugin') self.assertRegexp('plugin plugin', 'available.*Plugin plugin')
self.assertResponse('echo [plugin plugin]', 'Plugin') self.assertResponse('echo [plugin plugin]', 'Plugin')
def testPlugins(self):
self.assertRegexp('plugins join', '(Format.*Admin|Admin.*Format)')
self.assertRegexp('plugins plugin', 'Plugin')
def testList(self): def testList(self):
self.assertRegexp('plugin list', 'Plugin.*Utilities') self.assertRegexp('plugin list', 'Plugin.*Utilities')