from typing import Optional, Union


def str2bool(value: Union[str, bool]) -> Optional[bool]:
    """
    Convert a string or boolean to a boolean.
    """
    if isinstance(value, bool):
        return value

    if value.lower().strip() in ['true', '1', 'yes', 'y', 't']:
        return True
    elif value.lower().strip() in ['false', '0', 'no', 'n', 'f']:
        return False
    else:
        raise ValueError(f"Invalid boolean string: {value}. Must be one of: ['true', '1', 'yes', 'y', 't', 'false', '0', 'no', 'n', 'f']")
