mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
Allow abbreviation in getLiteral.
This commit is contained in:
parent
c809b7a14e
commit
ba1bb34729
@ -475,10 +475,12 @@ def getMatch(irc, msg, args, state, regexp, errmsg):
|
||||
irc.error(errmsg, Raise=True)
|
||||
|
||||
def getLiteral(irc, msg, args, state, literals, errmsg=None):
|
||||
# ??? Should we allow abbreviations?
|
||||
if isinstance(literals, basestring):
|
||||
literals = (literals,)
|
||||
if args[0] in literals:
|
||||
state.args.append(args.pop(0))
|
||||
abbrevs = utils.abbrev(literals)
|
||||
if args[0] in abbrevs:
|
||||
state.args.append(abbrevs[args.pop(0)])
|
||||
elif errmsg is not None:
|
||||
irc.error(errmsg, Raise=True)
|
||||
else:
|
||||
@ -710,7 +712,6 @@ class commalist(context):
|
||||
args[:] = original
|
||||
raise
|
||||
|
||||
|
||||
class getopts(context):
|
||||
"""The empty string indicates that no argument is taken; None indicates
|
||||
that there is no converter for the argument."""
|
||||
|
@ -111,7 +111,16 @@ class CommandsTestCase(SupyTestCase):
|
||||
self.assertState(spec, ['12,11,10,', '9'], [[12, 11, 10, 9]])
|
||||
spec.append('int')
|
||||
self.assertState(spec, ['12,11,10', '9'], [[12, 11, 10], 9])
|
||||
|
||||
|
||||
def testLiteral(self):
|
||||
spec = [('literal', ['foo', 'bar', 'baz'])]
|
||||
self.assertState(spec, ['foo'], ['foo'])
|
||||
self.assertState(spec, ['fo'], ['foo'])
|
||||
self.assertState(spec, ['f'], ['foo'])
|
||||
self.assertState(spec, ['bar'], ['bar'])
|
||||
self.assertState(spec, ['baz'], ['baz'])
|
||||
self.assertRaises(callbacks.ArgumentError,
|
||||
self.assertState, spec, ['ba'], ['baz'])
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user