import re
import click


def parse_host(host: str) -> str:
    """Check if host is valid.

    Parameters
    ----------
    host : str
        Possible host name.

    Returns
    -------
    host : str
        Valid host name

    Raises
    ------
    click.BadParameter
        If ``host`` is not ``localhost`` or a four digit number not starting
        with zero.

    """
    if host == 'localhost':
        return host
    elif re.fullmatch(r'^[1-9][0-9]{,3}', host):
        return host
    else:
        raise click.BadParameter(
            'ERROR: Use <localhost> or up to four digits not starting with '
            'zero.')