import click


def validate_user(context, param, value):
    """
    Validates the existence of user by username.
    """
    users = context.obj.api.users()
    user = next((u for u in users if u["username"] == value), None)
    if not user:
        raise click.BadParameter("User \"%s\" was not found" % value)

    return user