mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
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:
parent
9c5f05ab2d
commit
3005752c58
@ -67,7 +67,10 @@ class Plugin(callbacks.Plugin):
|
||||
def plugin(self, irc, msg, args, 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)
|
||||
L = []
|
||||
@ -89,6 +92,38 @@ class Plugin(callbacks.Plugin):
|
||||
irc.error(format('There is no command %q.', command))
|
||||
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
|
||||
|
||||
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')])
|
||||
|
||||
def author(self, irc, msg, args, cb):
|
||||
"""<plugin>
|
||||
|
||||
|
@ -30,11 +30,15 @@
|
||||
from supybot.test import *
|
||||
|
||||
class PluginTestCase(PluginTestCase):
|
||||
plugins = ('Plugin', 'Utilities')
|
||||
plugins = ('Plugin', 'Utilities', 'Admin', 'Format')
|
||||
def testPlugin(self):
|
||||
self.assertRegexp('plugin plugin', 'available.*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):
|
||||
self.assertRegexp('plugin list', 'Plugin.*Utilities')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user