import itertools


def styleguide_lint_with_options(request, styleguide_lint, config_write, tmp_path):
    """Fixture which will run the styleguide with the "lint" subcommand, given the provided options.

    The options will be tested on the command line as well as in the config.
    `base_args` and `lint_args` are similar to the `styleguide_lint` fixture, with the exception of
    being mappings from option name to value.
    """

    def _to_cmd_line(item):
        return (f"--{item[0].replace('_', '-')}", item[1])

    def runner(base_args={}, lint_args={}):
        if request.param:
            base_args_strs = []
            lint_args_strs = []
            config_write(**base_args, **lint_args)

        else:
            base_args_strs = itertools.chain(*map(_to_cmd_line, base_args.items()))
            lint_args_strs = itertools.chain(*map(_to_cmd_line, lint_args.items()))

        return styleguide_lint(base_args=base_args_strs, lint_args=lint_args_strs)

    return runner