from typing import Iterable
from typing import Tuple
import pathlib
import click


def validate_paths(ctx, param, value: Iterable[str]) -> Tuple[pathlib.Path]:
    """Return a list of git directories in the given paths."""
    git_dirs = []
    for path in value:
        for d in pathlib.Path(path).iterdir():
            if (d / ".git").exists():
                git_dirs.append(d)
    if git_dirs:
        return tuple(git_dirs)
    raise click.BadParameter("No git repositories were located.", ctx=ctx, param=param)