from typing import Union


def _tristate_bool_option(val: str) -> Union[None, bool]:
    """
    A parsing function for a tri-state boolean option.

    :raise ValueError:
        if not one of: `None`, true, 1, yes, on, false, 0, no, off
    """
    val = val and val.strip().lower()
    if not val:
        return None
    if val in "true 1 yes on".split():
        return True
    if val in "false 0 no off".split():
        return False
    raise ValueError(f"invalid boolean {val!r} supplied")