From 7d50378d25c1b20e4418daa79cdd7c2bfc7e5421 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 16 Oct 2013 22:55:16 +0300 Subject: Added combo options because why the hell not. --- optinterpreter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'optinterpreter.py') diff --git a/optinterpreter.py b/optinterpreter.py index e2f72d071..9d2353646 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: -- cgit v1.2.3