import click


def validate_new_relay_name(context, param, value):
    """
    Validates uniqueness of new relay name.
    """
    relays = context.obj.api.relays()
    exists = any(r for r in relays
                 if r["name"] == value)
    if exists:
        error = "Relay \"%s\" already exists" % value
        raise click.BadParameter(error)

    return value