summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/rich_click/utils.py
blob: 128f8b1b6d2952e8faf475764e3d162781f05873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from typing import Any, Optional


def truthy(o: Any) -> Optional[bool]:
    """Check if string or other obj is truthy."""
    if isinstance(o, str):
        if o.lower() in {"y", "yes", "t", "true", "1"}:
            return True
        elif o.lower() in {"n", "no", "f", "false", "0"}:
            return False
        else:
            return None
    elif o is None:
        return None
    else:
        return bool(o)