Allow abbreviation in getLiteral.

This commit is contained in:
Jeremy Fincher 2004-10-26 23:17:58 +00:00
parent c809b7a14e
commit ba1bb34729
2 changed files with 14 additions and 4 deletions

View File

@ -475,10 +475,12 @@ def getMatch(irc, msg, args, state, regexp, errmsg):
irc.error(errmsg, Raise=True) irc.error(errmsg, Raise=True)
def getLiteral(irc, msg, args, state, literals, errmsg=None): def getLiteral(irc, msg, args, state, literals, errmsg=None):
# ??? Should we allow abbreviations?
if isinstance(literals, basestring): if isinstance(literals, basestring):
literals = (literals,) literals = (literals,)
if args[0] in literals: abbrevs = utils.abbrev(literals)
state.args.append(args.pop(0)) if args[0] in abbrevs:
state.args.append(abbrevs[args.pop(0)])
elif errmsg is not None: elif errmsg is not None:
irc.error(errmsg, Raise=True) irc.error(errmsg, Raise=True)
else: else:
@ -710,7 +712,6 @@ class commalist(context):
args[:] = original args[:] = original
raise raise
class getopts(context): class getopts(context):
"""The empty string indicates that no argument is taken; None indicates """The empty string indicates that no argument is taken; None indicates
that there is no converter for the argument.""" that there is no converter for the argument."""

View File

@ -112,6 +112,15 @@ class CommandsTestCase(SupyTestCase):
spec.append('int') spec.append('int')
self.assertState(spec, ['12,11,10', '9'], [[12, 11, 10], 9]) 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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: