mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Fix crash for commands with ambiguous getopts shortcuts and no docstring.
This commit is contained in:
parent
18bafc725f
commit
6f9960d7a4
@ -1288,7 +1288,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.') % ' '.join(command))
|
||||
else:
|
||||
irc.reply(help)
|
||||
except (SyntaxError, Error) as e:
|
||||
|
@ -28,6 +28,7 @@
|
||||
###
|
||||
|
||||
import sys
|
||||
import getopt
|
||||
|
||||
from supybot.test import *
|
||||
|
||||
@ -119,6 +120,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]])
|
||||
@ -184,5 +196,21 @@ class FirstTestCase(CommandsTestCase):
|
||||
self.assertStateErrored([first('int', 'something')], ['words'],
|
||||
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'})],
|
||||
checkDoc=False)
|
||||
|
||||
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