from pathlib import Path
from typing import Dict


def get_actual_envrc_variables(path_envrc: Path) -> Dict[str, Path]:
    """Get the export variables and values for directories in the `.envrc` file of the
    `govcookiecutter` template.

    Args:
        path_envrc: A file path to the `.envrc` file of the `govcookiecutter` template.

    Returns:
        A dictionary where the keys are the names of the export directory variables,
        and the values are the export directory values.

    """

    # Instantiate a saving dictionary variable
    envrc_actual_dir_variable = {}

    # Open the `path_envrc` file, and get all export variables starting with `DIR`, and
    # the values assigned to them, and return the output
    with path_envrc.open() as f:
        for line in f.readlines():
            if line.startswith("export DIR"):
                k, v = (
                    line.lstrip("export ")
                    .strip()
                    .replace("$(pwd)", path_envrc.parent.name)
                    .split("=")
                )
                envrc_actual_dir_variable[k] = Path(v)
    return envrc_actual_dir_variable