import click


def open_file_mode_option(**kwargs):
    """Get open mode file option

    Parameters
    ----------
    **kwargs
        All kwargs are passed to click.option.

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

    def custom_open_file_mode_option(func):
        def callback(ctx, param, value):
            if value not in ["w", "a", "w+", "a+"]:
                raise click.BadParameter("Incorrect open file mode")
            ctx.meta["open_mode"] = value
            return value

        return click.option(
            "-om",
            "--open-mode",
            default="w",
            help="File open mode",
            callback=callback,
            **kwargs,
        )(func)

    return custom_open_file_mode_option