diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-12-02 19:54:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-02 19:54:27 +0200 |
commit | 793fc002fa3c414cee20b3b3a4397eeb3ce3d35e (patch) | |
tree | 6d299980e2bdb44823e3dd109037241a5f8498df /mesonbuild/optinterpreter.py | |
parent | e1bdc098ca48990322b058e2a2a9fce16c3e7674 (diff) | |
parent | c9351ce30c03d107279090da7825096951a705d3 (diff) | |
download | meson-793fc002fa3c414cee20b3b3a4397eeb3ce3d35e.zip meson-793fc002fa3c414cee20b3b3a4397eeb3ce3d35e.tar.gz meson-793fc002fa3c414cee20b3b3a4397eeb3ce3d35e.tar.bz2 |
Merge pull request #2390 from dcbaker/submit/options-list
Add an array type to user options
Diffstat (limited to 'mesonbuild/optinterpreter.py')
-rw-r--r-- | mesonbuild/optinterpreter.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index 01dd036..22a263e 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -84,9 +84,25 @@ def ComboParser(name, description, kwargs): raise OptionException('Combo choice elements must be strings.') return coredata.UserComboOption(name, description, choices, kwargs.get('value', choices[0])) +@permitted_kwargs({'value', 'choices'}) +def string_array_parser(name, description, kwargs): + if 'choices' not in kwargs: + raise OptionException('Array option missing "choices" keyword.') + choices = kwargs['choices'] + if not isinstance(choices, list): + raise OptionException('Array choices must be an array.') + for i in choices: + if not isinstance(i, str): + raise OptionException('Array choice elements must be strings.') + value = kwargs.get('value', choices) + if not isinstance(value, list): + raise OptionException('Array choices must be passed as an array.') + return coredata.UserStringArrayOption(name, description, value, choices=choices) + option_types = {'string': StringParser, 'boolean': BooleanParser, 'combo': ComboParser, + 'array': string_array_parser, } class OptionInterpreter: |