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: Christian Heimes <christian@python.org>
This commit is contained in:
Christian Heimes 2018-05-07 19:12:47 +02:00 committed by Łukasz Langa
parent 8325f893b4
commit 2d9eaafa97
2 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -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()