def parse_port(arg):
    """Parse port argument and raise ValueError if invalid"""
    if not arg:
        return None
    arg = int(arg)
    if arg < 1 or arg > 65535:
        raise ValueError("invalid port value!")
    return arg