Bug 1257104 - Allow options with choices and possibly no given values
While rare, this is something we support for e.g. --enable-eme, where it
can be either given with no values, "adobe", some future other EME GMP
adapter names, or a combination of them.
--- a/python/mozbuild/mozbuild/configure/options.py
+++ b/python/mozbuild/mozbuild/configure/options.py
@@ -214,20 +214,16 @@ class Option(object):
if has_choices and not all(d in choices for d in self.default):
raise InvalidOptionError(
'The `default` value must be one of %s' %
', '.join("'%s'" % c for c in choices))
elif has_choices:
maxargs = self.maxargs
if len(choices) < maxargs and maxargs != sys.maxint:
raise InvalidOptionError('Not enough `choices` for `nargs`')
- if self.minargs == 0:
- raise InvalidOptionError(
- '%s is not a valid `nargs` when `choices` are given'
- % str(nargs))
self.choices = choices
self.help = help
@staticmethod
def split_option(option):
'''Split a flag or variable into a prefix, a name and values
Variables come in the form NAME=values (no prefix).
--- a/python/mozbuild/mozbuild/test/configure/test_options.py
+++ b/python/mozbuild/mozbuild/test/configure/test_options.py
@@ -154,28 +154,19 @@ class TestOption(unittest.TestCase):
self.assertEquals(opt.option,
option.replace('-enable-', '-disable-')
.replace('-with-', '-without-'))
self.assertEquals(Option(env='FOO').option, 'FOO')
def test_option_choices(self):
with self.assertRaises(InvalidOptionError):
- Option('--option', nargs=0, choices=('a', 'b'))
-
- with self.assertRaises(InvalidOptionError):
Option('--option', nargs=3, choices=('a', 'b'))
with self.assertRaises(InvalidOptionError):
- Option('--option', nargs='?', choices=('a', 'b'))
-
- with self.assertRaises(InvalidOptionError):
- Option('--option', nargs='*', choices=('a', 'b'))
-
- with self.assertRaises(InvalidOptionError):
Option('--without-option', nargs=1, choices=('a', 'b'))
with self.assertRaises(InvalidOptionError):
Option('--without-option', nargs='+', choices=('a', 'b'))
with self.assertRaises(InvalidOptionError):
Option('--without-option', default='c', choices=('a', 'b'))