import functools


def require(*requirements, none_on_failure=False):
    """Decorator that can be used to require requirements.

    :param requirements: List of requirements that should be verified
    :param none_on_failure: If true, does not raise a PrerequisiteFailedError, but instead returns None
    """

    def inner(f):
        @functools.wraps(f)
        def wrapper(*args, **kwargs):
            for req in requirements:
                if none_on_failure:
                    if not req.is_available:
                        return None
                else:
                    req.require()
            return f(*args, **kwargs)
        return wrapper
    return inner