Added combo options because why the hell not.

pull/15/head
Jussi Pakkanen 11 years ago
parent 07b7d63ccb
commit 7d50378d25
  1. 16
      optinterpreter.py
  2. 4
      test cases/common/47 options/meson.build
  3. 1
      test cases/common/47 options/meson_options.txt

@ -38,8 +38,24 @@ class UserBooleanOption(UserOption):
if not isinstance(self.value, bool):
raise OptionException('Value of boolean option is not boolean.')
class UserComboOption(UserOption):
def __init__(self, kwargs):
super().__init__(kwargs)
if 'choices' not in kwargs:
raise OptionException('Combo option missing "choices" keyword.')
self.choices = kwargs['choices']
if not isinstance(self.choices, list):
raise OptionException('Combo choices must be an array.')
for i in self.choices:
if not isinstance(i, str):
raise OptionException('Combo choice elements must be strings.')
self.value = kwargs.get('value', self.choices[0])
if self.value not in self.choices:
raise OptionException('Combo value must be one of the choices.')
option_types = {'string' : UserStringOption,
'boolean' : UserBooleanOption,
'combo' : UserComboOption,
}
class OptionInterpreter:

@ -7,3 +7,7 @@ endif
if get_option('other_one') != false
error('Incorrect value to boolean option.')
endif
if get_option('combo_opt') != 'combo'
error('Incorrect value to combo option.')
endif

@ -1,2 +1,3 @@
option('testoption', type : 'string', value : 'optval')
option('other_one', type : 'boolean', value : false)
option('combo_opt', type : 'combo', choices : ['one', 'two', 'combo'], value : 'combo')

Loading…
Cancel
Save