import click


def bool_option(name, short_name, desc, dflt=False, **kwargs):
    """Generic provider for boolean options

    Parameters
    ----------
    name : str
        name of the option
    short_name : str
        short name for the option
    desc : str
        short description for the option
    dflt : bool or None
        Default value
    **kwargs
        All kwargs are passed to click.option.

    Returns
    -------
    ``callable``
        A decorator to be used for adding this option.
    """

    def custom_bool_option(func):
        def callback(ctx, param, value):
            ctx.meta[name.replace("-", "_")] = value
            return value

        return click.option(
            "-%s/-n%s" % (short_name, short_name),
            "--%s/--no-%s" % (name, name),
            default=dflt,
            help=desc,
            show_default=True,
            callback=callback,
            is_eager=True,
            **kwargs,
        )(func)

    return custom_bool_option