aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2013-10-16 22:55:16 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2013-10-16 22:55:16 +0300
commit7d50378d25c1b20e4418daa79cdd7c2bfc7e5421 (patch)
tree1a91d7855dc2ab37f9695713d56ebca36424ef7a
parent07b7d63ccb69304610440970db4e52ba14e15643 (diff)
downloadmeson-7d50378d25c1b20e4418daa79cdd7c2bfc7e5421.zip
meson-7d50378d25c1b20e4418daa79cdd7c2bfc7e5421.tar.gz
meson-7d50378d25c1b20e4418daa79cdd7c2bfc7e5421.tar.bz2
Added combo options because why the hell not.
-rw-r--r--optinterpreter.py16
-rw-r--r--test cases/common/47 options/meson.build4
-rw-r--r--test cases/common/47 options/meson_options.txt1
3 files changed, 21 insertions, 0 deletions
diff --git a/optinterpreter.py b/optinterpreter.py
index e2f72d0..9d23536 100644
--- a/optinterpreter.py
+++ b/optinterpreter.py
@@ -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:
diff --git a/test cases/common/47 options/meson.build b/test cases/common/47 options/meson.build
index 5d6f3d0..6604d8a 100644
--- a/test cases/common/47 options/meson.build
+++ b/test cases/common/47 options/meson.build
@@ -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
diff --git a/test cases/common/47 options/meson_options.txt b/test cases/common/47 options/meson_options.txt
index 3dcb62d..fcd3db4 100644
--- a/test cases/common/47 options/meson_options.txt
+++ b/test cases/common/47 options/meson_options.txt
@@ -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')