mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-14 22:49:23 +01:00
Fix crash for commands with ambiguous getopts shortcuts and no docstring.
Signed-off-by: James McCoy <vega.james@gmail.com>
This commit is contained in:
parent
cffbd959e8
commit
b0846f914e
@ -1207,7 +1207,7 @@ class Commands(BasePlugin):
|
||||
utils.exnToString(e))
|
||||
help = self.getCommandHelp(command)
|
||||
if help.endswith('command has no help.'):
|
||||
irc.error('Invalid arguments for %s.' % method.__name__)
|
||||
irc.error('Invalid arguments for %s.' % formatCommand(command))
|
||||
else:
|
||||
irc.reply(help)
|
||||
except (SyntaxError, Error), e:
|
||||
|
@ -28,6 +28,8 @@
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
###
|
||||
|
||||
import getopt
|
||||
|
||||
from supybot.test import *
|
||||
|
||||
from supybot.commands import *
|
||||
@ -117,6 +119,17 @@ class GeneralContextTestCase(CommandsTestCase):
|
||||
['12', '--foo', 'baz', '--bar', '13', '15'],
|
||||
[12, [('foo', 'baz'), ('bar', 13)], 15])
|
||||
|
||||
def testGetoptsShort(self):
|
||||
spec = ['int', getopts({'foo': None, 'bar': 'int'}), 'int']
|
||||
self.assertState(spec,
|
||||
['12', '--f', 'baz', '--ba', '13', '15'],
|
||||
[12, [('foo', 'baz'), ('bar', 13)], 15])
|
||||
|
||||
def testGetoptsConflict(self):
|
||||
spec = ['int', getopts({'foo': None, 'fbar': 'int'}), 'int']
|
||||
self.assertRaises(getopt.GetoptError, self.assertStateErrored,
|
||||
spec, ['12', '--f', 'baz', '--ba', '13', '15'])
|
||||
|
||||
def testAny(self):
|
||||
self.assertState([any('int')], ['1', '2', '3'], [[1, 2, 3]])
|
||||
self.assertState([None, any('int')], ['1', '2', '3'], ['1', [2, 3]])
|
||||
@ -186,5 +199,19 @@ class FirstTestCase(CommandsTestCase):
|
||||
spec = [first('regexpMatcher', 'regexpReplacer'), 'text']
|
||||
self.assertStateErrored(spec, ['s/foo/bar/', 'x' * 512], errored=False)
|
||||
|
||||
class GetoptTestCase(PluginTestCase):
|
||||
plugins = ('Misc',) # We put something so it does not complain
|
||||
class Foo(callbacks.Plugin):
|
||||
def bar(self, irc, msg, args, optlist):
|
||||
irc.reply(' '.join(sorted(['%s:%d'%x for x in optlist])))
|
||||
bar = wrap(bar, [getopts({'foo': 'int', 'fbar': 'int'})])
|
||||
|
||||
def testGetoptsExact(self):
|
||||
self.irc.addCallback(self.Foo(self.irc))
|
||||
self.assertResponse('bar --foo 3 --fbar 4', 'fbar:4 foo:3')
|
||||
self.assertResponse('bar --fo 3 --fb 4', 'fbar:4 foo:3')
|
||||
self.assertResponse('bar --f 3 --fb 5',
|
||||
'Error: Invalid arguments for bar.')
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user