import click


def plugin_callback(ctx, param, value):
    """
    Load correct plugin and add it into the context
    """
    config = ctx.obj["config"]

    # Selection through CLI
    if value:
        ctx.ensure_object(dict)
        ctx.obj[param.name] = value
        return value

    # Selection through configuration file
    value = config.get("main.default_{}_plugin".format(param.name), None)

    if value:
        return value

    raise click.BadParameter("{} plugin not set".format(param.name))