Repository: psf/black
File: src/black/__init__.py (Python)

Code before:
    force_exclude: Optional[Pattern[str]],
    stdin_filename: Optional[str],
    workers: int,
    src: Tuple[str, ...],
    config: Optional[str],
) -> None:
    """The uncompromising code formatter."""
    ctx.ensure_object(dict)

    if src and code is not None:
        out(
            main.get_usage(ctx)
            + "\n\n'SRC' and 'code' cannot be passed simultaneously."
        )
        ctx.exit(1)
    if not src and code is None:
        out(main.get_usage(ctx) + "\n\nOne of 'SRC' or 'code' is required.")
        ctx.exit(1)

    if stdin_filename is not None:
        src_with_stdin_filename = tuple(stdin_filename if s == "-" else s for s in src)
    else:
        src_with_stdin_filename = src
    root, method = (
        find_project_root(src_with_stdin_filename) if code is None else (None, None)
    )
    ctx.obj["root"] = root

    if verbose:
        if root:
            out(
                f"Identified `{root}` as project root containing a {method}.",
                fg="blue",
            )

            normalized = [
                (source, source)
                if source == "-"
                else (normalize_path_maybe_ignore(Path(source), root), source)
                for source in src
            ]
            srcs_string = ", ".join(
                [
                    f'"{_norm}"'
                    if _norm
                    else f'\033[31m"{source} (skipping - invalid)"\033[34m'
                    for _norm, source in normalized
                ]
            )
            out(f"Sources to be formatted: {srcs_string}", fg="blue")


Review comment (suggestion):
```suggestion
    if stdin_filename is not None:
        src = tuple(stdin_filename if s == "-" else s for s in src)

    root, method = find_project_root(src) if code is None else (None, None)
```

Perhaps we could make the above work below as well.

Also, I was unaware how passing multiple stdin placeholders works, but for `- - -` etc stdin is only read once (or does closing it prevent further reads, guess so), and with other files `-` is read as a filename. So it is safe to assume that there will only be one to convert. Or maybe we'll have to even guard against weird use, not sure what would be best.

Yeah, tests would be nice 👍

Code after:
    force_exclude: Optional[Pattern[str]],
    stdin_filename: Optional[str],
    workers: int,
    src: Tuple[str, ...],
    config: Optional[str],
) -> None:
    """The uncompromising code formatter."""
    ctx.ensure_object(dict)

    if src and code is not None:
        out(
            main.get_usage(ctx)
            + "\n\n'SRC' and 'code' cannot be passed simultaneously."
        )
        ctx.exit(1)
    if not src and code is None:
        out(main.get_usage(ctx) + "\n\nOne of 'SRC' or 'code' is required.")
        ctx.exit(1)

    root, method = (
        find_project_root(src, stdin_filename) if code is None else (None, None)
    )
    ctx.obj["root"] = root

    if verbose:
        if root:
            out(
                f"Identified `{root}` as project root containing a {method}.",
                fg="blue",
            )

            normalized = [
                (source, source)
                if source == "-"
                else (normalize_path_maybe_ignore(Path(source), root), source)
                for source in src
            ]
            srcs_string = ", ".join(
                [
                    f'"{_norm}"'
                    if _norm
                    else f'\033[31m"{source} (skipping - invalid)"\033[34m'
                    for _norm, source in normalized
                ]
            )
            out(f"Sources to be formatted: {srcs_string}", fg="blue")

        if config:
            config_source = ctx.get_parameter_source("config")
            user_level_config = str(find_user_pyproject_toml())
            if config == user_level_config: