import click


def validate_command(context, param, value):
    """
    Validates the existance of a command.  Gets the command by name,
    returning it if it exists and throwing a BadParameter error if it does
    not.
    """
    segments = value.split(":")
    if len(segments) != 2:
        raise click.BadParameter("Command \"%s\" was not found" % value)

    [bundle, command] = segments
    command = context.obj.api.command_by_name(bundle, command)
    if not command:
        raise click.BadParameter("Command \"%s\" was not found" % value)

    return command