import fnmatch
import click


def _match_pattern(what, items, pattern):
    """
    Match given pattern against given items.

    Parameters
    ----------
    what: str
        Describes what is filterd.
    items: Iterable[str]
        Items to be filtered
    include_pattern: str
        Comma separated items which should be included. Can contain glob patterns.
    """
    result = set()
    for part in pattern.split(","):
        found = set(fnmatch.filter(items, part.strip()))
        if not found:
            raise click.UsageError(
                "Could not find {what} {part}".format(what=what, part=part)
            )
        result |= found
    return result