from pathlib import Path


def can_override(path: Path, override: bool) -> Path:
    """Check if it's allowed to override a `path`.

    Args:
        path: path, where we are going to write
        override: permission to override flag

    Returns:
        The input `path`to facilitate chaining in mapping in code.

    Raises:
        FileExistsError: if file exists, but override is not allowed.
    """
    if not override and path.exists():
        raise FileExistsError(
            f"File {path} already exists."
            "Consider to use '--override' command line option or remove the file."
        )
    return path