@cli.command()
@common_options
@core_options
@click.option('-f', '--force', is_flag=True, help='skip the confirmation prompt and go straight to applying fixes. **Use this with caution.**')
@click.option('--fixed-suffix', default=None, help='An optional suffix to add to fixed files.')
@click.option('--parallel', type=int, default=1, help='If set to a value higher than 1, run SQLFluff in parallel, speeding up processing.')
@click.argument('paths', nargs=(- 1))
def fix(force, paths, parallel, bench=False, fixed_suffix='', logger=None, **kwargs):
    "Fix SQL files.\n\n    PATH is the path to a sql file or directory to lint. This can be either a\n    file ('path/to/file.sql'), a path ('directory/of/sql/files'), a single ('-')\n    character to indicate reading from *stdin* or a dot/blank ('.'/' ') which will\n    be interpreted like passing the current working directory as a path argument.\n    "
    fixing_stdin = (('-',) == paths)
    c = get_config(**kwargs)
    (lnt, formatter) = get_linter_and_formatter(c, silent=fixing_stdin)
    verbose = c.get('verbose')
    formatter.dispatch_config(lnt)
    set_logging_level(verbosity=verbose, logger=logger, stderr_output=fixing_stdin)
    if fixing_stdin:
        stdin = sys.stdin.read()
        result = lnt.lint_string_wrapped(stdin, fname='stdin', fix=True)
        stdout = result.paths[0].files[0].fix_string()[0]
        click.echo(stdout, nl=False)
        sys.exit()
    click.echo('==== finding fixable violations ====')
    try:
        result = lnt.lint_paths(paths, fix=True, ignore_non_existent_files=False, parallel=parallel)
    except IOError:
        click.echo(colorize('The path(s) {0!r} could not be accessed. Check it/they exist(s).'.format(paths), 'red'))
        sys.exit(1)
    if (result.num_violations(types=SQLLintError, fixable=True) > 0):
        click.echo('==== fixing violations ====')
        click.echo('{0} fixable linting violations found'.format(result.num_violations(types=SQLLintError, fixable=True)))
        if force:
            click.echo((colorize('FORCE MODE', 'red') + ': Attempting fixes...'))
            success = do_fixes(lnt, result, formatter, types=SQLLintError, fixed_file_suffix=fixed_suffix)
            if (not success):
                sys.exit(1)
        else:
            click.echo('Are you sure you wish to attempt to fix these? [Y/n] ', nl=False)
            c = click.getchar().lower()
            click.echo('...')
            if (c in ('y', '\r', '\n')):
                click.echo('Attempting fixes...')
                success = do_fixes(lnt, result, formatter, types=SQLLintError, fixed_file_suffix=fixed_suffix)
                if (not success):
                    sys.exit(1)
                else:
                    click.echo('All Finished 📜 🎉!')
            elif (c == 'n'):
                click.echo('Aborting...')
            else:
                click.echo("Invalid input, please enter 'Y' or 'N'")
                click.echo('Aborting...')
    else:
        click.echo('==== no fixable linting violations found ====')
        if (result.num_violations(types=SQLLintError, fixable=False) > 0):
            click.echo('  [{0} unfixable linting violations found]'.format(result.num_violations(types=SQLLintError, fixable=False)))
        click.echo('All Finished 📜 🎉!')
    if bench:
        click.echo('==== overall timings ====')
        timing_summary = result.timing_summary()
        for step in timing_summary:
            click.echo(f'=== {step} ===')
            click.echo(cli_table(timing_summary[step].items()))
    sys.exit(0)
Fix SQL files.

PATH is the path to a sql file or directory to lint. This can be either a
file ('path/to/file.sql'), a path ('directory/of/sql/files'), a single ('-')
character to indicate reading from *stdin* or a dot/blank ('.'/' ') which will
be interpreted like passing the current working directory as a path argument.
@cli.command()
@common_options
@core_options
@click.option('-f', '--force', is_flag=True, help='skip the confirmation prompt and go straight to applying fixes. **Use this with caution.**')
@click.option('--fixed-suffix', default=None, help='An optional suffix to add to fixed files.')
@click.option('--parallel', type=int, default=1, help='If set to a value higher than 1, run SQLFluff in parallel, speeding up processing.')
@click.argument('paths', nargs=(- 1))
def fix(force, paths, parallel, bench=False, fixed_suffix=, logger=None, **kwargs):
    "Fix SQL files.\n\n    PATH is the path to a sql file or directory to lint. This can be either a\n    file ('path/to/file.sql'), a path ('directory/of/sql/files'), a single ('-')\n    character to indicate reading from *stdin* or a dot/blank ('.'/' ') which will\n    be interpreted like passing the current working directory as a path argument.\n    "
    fixing_stdin = (('-',) == paths)
    c = get_config(**kwargs)
    (lnt, formatter) = get_linter_and_formatter(c, silent=fixing_stdin)
    verbose = c.get('verbose')
    formatter.dispatch_config(lnt)
    set_logging_level(verbosity=verbose, logger=logger, stderr_output=fixing_stdin)
    if fixing_stdin:
        stdin = sys.stdin.read()
        result = lnt.lint_string_wrapped(stdin, fname='stdin', fix=True)
        stdout = result.paths[0].files[0].fix_string()[0]
        click.echo(stdout, nl=False)
        sys.exit()
    click.echo('==== finding fixable violations ====')
    try:
        result = lnt.lint_paths(paths, fix=True, ignore_non_existent_files=False, parallel=parallel)
    except IOError:
        click.echo(colorize('The path(s) {0!r} could not be accessed. Check it/they exist(s).'.format(paths), 'red'))
        sys.exit(1)
    if (result.num_violations(types=SQLLintError, fixable=True) > 0):
        click.echo('==== fixing violations ====')
        click.echo('{0} fixable linting violations found'.format(result.num_violations(types=SQLLintError, fixable=True)))
        if force:
            click.echo((colorize('FORCE MODE', 'red') + ': Attempting fixes...'))
            success = do_fixes(lnt, result, formatter, types=SQLLintError, fixed_file_suffix=fixed_suffix)
            if (not success):
                sys.exit(1)
        else:
            click.echo('Are you sure you wish to attempt to fix these? [Y/n] ', nl=False)
            c = click.getchar().lower()
            click.echo('...')
            if (c in ('y', '\r', '\n')):
                click.echo('Attempting fixes...')
                success = do_fixes(lnt, result, formatter, types=SQLLintError, fixed_file_suffix=fixed_suffix)
                if (not success):
                    sys.exit(1)
                else:
                    click.echo('All Finished 📜 🎉!')
            elif (c == 'n'):
                click.echo('Aborting...')
            else:
                click.echo("Invalid input, please enter 'Y' or 'N'")
                click.echo('Aborting...')
    else:
        click.echo('==== no fixable linting violations found ====')
        if (result.num_violations(types=SQLLintError, fixable=False) > 0):
            click.echo('  [{0} unfixable linting violations found]'.format(result.num_violations(types=SQLLintError, fixable=False)))
        click.echo('All Finished 📜 🎉!')
    if bench:
        click.echo('==== overall timings ====')
        timing_summary = result.timing_summary()
        for step in timing_summary:
            click.echo(f'=== {step} ===')
            click.echo(cli_table(timing_summary[step].items()))
    sys.exit(0)