aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/util.py
diff options
context:
space:
mode:
authorNick Brassel <[email protected]>2024-11-08 15:57:22 +1100
committerGitHub <[email protected]>2024-11-08 04:57:22 +0000
commit580d18d2e9a9cb08f11439d5dd58d8e3adffd17f (patch)
tree761d0572fc7b46ddfbe2487e4f9684a26e8abc16 /lib/python/qmk/util.py
parent4f9ef90754a79774da5685b786403c130d836ac4 (diff)
downloadqmk_firmware-580d18d2e9a9cb08f11439d5dd58d8e3adffd17f.tar.gz
qmk_firmware-580d18d2e9a9cb08f11439d5dd58d8e3adffd17f.zip
Speed improvements to `qmk find`. (#24385)
Diffstat (limited to 'lib/python/qmk/util.py')
-rw-r--r--lib/python/qmk/util.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/python/qmk/util.py b/lib/python/qmk/util.py
index b73fab89d1..8f99410e1d 100644
--- a/lib/python/qmk/util.py
+++ b/lib/python/qmk/util.py
@@ -27,6 +27,27 @@ def maybe_exit_config(should_exit: bool = True, should_reraise: bool = False):
maybe_exit_reraise = should_reraise
+def truthy(value, value_if_unknown=False):
+ """Returns True if the value is truthy, False otherwise.
+
+ Deals with:
+ True: 1, true, t, yes, y, on
+ False: 0, false, f, no, n, off
+ """
+ if value in {False, True}:
+ return bool(value)
+
+ test_value = str(value).strip().lower()
+
+ if test_value in {"1", "true", "t", "yes", "y", "on"}:
+ return True
+
+ if test_value in {"0", "false", "f", "no", "n", "off"}:
+ return False
+
+ return value_if_unknown
+
+
@contextlib.contextmanager
def parallelize():
"""Returns a function that can be used in place of a map() call.