From 756396d7584800324996def0145485b77ee7775b Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 28 Jun 2019 23:25:24 +0100 Subject: Implement utils.OptionsSetting --- src/utils/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 5ad057c8..545360c8 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -257,3 +257,15 @@ class IntSetting(Setting): return int(stripped) return None +class OptionsSetting(Setting): + def __init__(self, name: str, options: typing.List[str], help: str=None, + example: str=None): + self._options = options + Setting.__init__(name, help, example) + + def parse(self, value: str) -> typing.Any: + value_lower = value.lower() + for option in self._options: + if option.lower() == value_lower: + return option + return None -- cgit v1.3.1-10-gc9f91