Repository: dask/dask
File: dask/cli.py (Python)

Code before:
        except KeyError:
            click.echo(click.style(f"Section not found: {key}", fg="red"), err=True)
            exit(1)


@config.command(name="find")
@click.argument("key", required=True)
def config_find(key):
    """Find a Dask config key by searching config location paths"""
    paths = list(dask.config.paths_containing_key(key))
    if paths:
        click.echo(f"Found [{key}] in the following files:")
        max_len = len(str(max(paths, key=lambda v: len(str(v)))))
        for path in paths:
            config = dask.config.collect_yaml([path])[0]
            value = dask.config.get(key, config=config)
            spacing = " " * (max_len - len(str(path)))
            click.echo(f"{path} {spacing} [{key}={value}]")
    else:
        click.echo(f"Unable to find [{key}] in any of the following paths:")
        click.echo("\n".join(map(str, dask.config.paths)))


@config.command(name="set")
@click.argument("key", default=None, required=True)
@click.argument("value", default=None, required=True)
@click.option(
    "--file",
    default=None,
    required=False,
    type=pathlib.Path,
    help=(
        "File to use, defaulting to the first config file containing the key, "
        "'DASK_CONFIG' environment variable location or finally, "
        "'~/.config/dask/dask.yaml'"
    ),
)
def config_set(key, value, file):
    """Set a Dask config key to a new value"""
    value = dask.config.interpret_value(value)
    _, path = save_config(key, value, file)
    click.echo(f"Updated [{key}] to [{value}], config saved to {path}")


def save_config(
    key: str,
    value: Any,
    config_file: pathlib.Path | None = None,
) -> tuple[dict, pathlib.Path]:
    """
    Save new config values to dask config file,

Review comment (suggestion):
```suggestion
@click.argument("key", required=True)
@click.argument("value", required=True)
```

Code after:
    """Find a Dask config key by searching config location paths"""
    paths = list(dask.config.paths_containing_key(key))
    if paths:
        click.echo(f"Found [{key}] in the following files:")
        max_len = len(str(max(paths, key=lambda v: len(str(v)))))
        for path in paths:
            config = next(dask.config.collect_yaml([path]))
            value = dask.config.get(key, config=config)
            spacing = " " * (max_len - len(str(path)))
            click.echo(f"{path} {spacing} [{key}={value}]")
    else:
        click.echo(f"Unable to find [{key}] in any of the following paths:")
        click.echo("\n".join(map(str, dask.config.paths)))


@config.command(name="set")
@click.argument("key", required=True)
@click.argument("value", required=True)
@click.option(
    "--file",
    default=None,
    required=False,
    type=pathlib.Path,
    help=(
        "File to use, defaulting to the first config file containing the key, "
        "'DASK_CONFIG' environment variable location or finally, "
        "'~/.config/dask/dask.yaml'"
    ),
)
def config_set(key, value, file):
    """Set a Dask config key to a new value"""
    value = dask.config.interpret_value(value)
    _, path = save_config(key, value, file)
    click.echo(f"Updated [{key}] to [{value}], config saved to {path}")


def save_config(
    key: str,
    value: Any,
    config_file: pathlib.Path | None = None,
) -> tuple[dict, pathlib.Path]:
    """
    Save new config values to dask config file,
    return new config and path to file.
    """
    # If explicit config file wasn't supplied, try finding the first existing
    # config file w/ this key, falling back to the default config path
    if config_file is None:
        config_file = next(
            dask.config.paths_containing_key(key),
            pathlib.Path(dask.config.PATH) / "dask.yaml",