import re
import click


def parse_port(port: str) -> str:
    """Check if port is valid.

    Parameters
    ----------
    port : str
        Possible port name.

    Returns
    -------
    port : str
        Valid port name

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

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