from typing import Tuple


def parse_host_and_port(val: str) -> Tuple[str, int, bool]:
    """This takes a command line argument specifying a host/port and returns
    a tuple of (host, port, bound) to determine a TCP endpoint:

    5000            -> ("*", 5000, True)
    localhost:5000  -> ("localhost", 5000, False)
    *:5000          -> ("*", 5000, True)
    L5000           -> ("localhost", 5000, False)
    """

    parts = val.split(":")

    if len(parts) == 1:

        s = parts[0]
        if s[0] == "L":
            port = int(s[1:])
            host = "localhost"
            bound = False
        else:
            port = int(s)
            host = "*"
            bound = True

    else:

        host = parts[0]
        port = int(parts[1])
        bound = host == "*"

    return (host, port, bound)