Commit 2d9eaafa authored by Christian Heimes's avatar Christian Heimes Committed by Łukasz Langa
Browse files

Output something when no files are reformatted (#190)

Just executing ``black`` without any argument does not print any message
to stdout or stderr. It's rather confusing, because the user doesn't
know what happened.

In ``len(sources) == 0`` case, black now prints ``No paths given. Nothing to
do``.

Signed-off-by: default avatarChristian Heimes <christian@python.org>
parent 8325f893
Loading
Loading
Loading
Loading
+1 −0
Changes for black.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -192,6 +192,7 @@ def main(
        write_back = WriteBack.YES
    report = Report(check=check, quiet=quiet)
    if len(sources) == 0:
        out("No paths given. Nothing to do 😴")
        ctx.exit(0)
        return

+6 −0
Changes for tests/test_black.py: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -636,6 +636,12 @@ def test_check_diff_use_together(self) -> None:
            )
            self.assertEqual(result.exit_code, 1)

    def test_no_files(self) -> None:
        with cache_dir():
            # Without an argument, black exits with error code 0.
            result = CliRunner().invoke(black.main, [])
            self.assertEqual(result.exit_code, 0)

    def test_read_cache_line_lengths(self) -> None:
        with cache_dir() as workspace:
            path = (workspace / "file.py").resolve()