From ee958971e85f9d45ef087675a08aca49050b2526 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Sat, 19 Dec 2020 02:37:54 +0100 Subject: [PATCH] Implement boolean configs --- lib/config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/config.py b/lib/config.py index 545c478..b34e353 100644 --- a/lib/config.py +++ b/lib/config.py @@ -83,6 +83,16 @@ def _config_set_in_scope(scope: dict, key: str, value, cfg_type: type) -> str: elif cfg_type == float: scope[key] = float(value) success = True + elif cfg_type == bool: + value = value.lower() + if value in ('true', '1', 'yes', 'y', 'positive', 'enable', 'en'): + value = True + elif value in ('false', '0', 'no', 'n', 'negative', 'disable', 'dis'): + value = False + else: + return 'Unable to convert given value to a boolean!' + scope[key] = value + success = True except (TypeError, ValueError): success = False if success: