import click


def valid_which_fold(ctx, param, value):
    """
    A click callback that checks if the --which-fold argument is between
    1 and --num-folds. If not, raises a click.BadParameter
    """
    if value is not None:
        if not (1 <= value <= ctx.obj.num_folds):
            raise click.BadParameter(("--which-fold ({which_fold}) must be between 1 and "
                                     "--num-folds ({num_folds}) inclusive").format(
                                     which_fold=value, num_folds=ctx.obj.num_folds))
    return value