diff --git a/CHANGELOG.md b/CHANGELOG.md index d91f51254..2379e78d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Changelog NOTE: isort follows the [semver](https://semver.org/) versioning standard. +### 5.2.2 July 30, 2020 + - Fixed #1356: return status when arguments are passed in without files or a content stream. + ### 5.2.1 July 28, 2020 - Update precommit to default to filtering files that are defined in skip. - Improved relative path detection for `skip` config usage. diff --git a/isort/main.py b/isort/main.py index 99a37b07e..30cf8f4ce 100644 --- a/isort/main.py +++ b/isort/main.py @@ -739,7 +739,10 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] = file_names = arguments.pop("files", []) if not file_names and not show_config: print(QUICK_GUIDE) - return + if arguments: + sys.exit(f"Error: arguments passed in without any paths or content.") + else: + return elif file_names == ["-"] and not show_config: arguments.setdefault("settings_path", os.getcwd()) api.sort_stream( diff --git a/tests/test_main.py b/tests/test_main.py index bc4df4e91..1c980c1f0 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -99,12 +99,18 @@ def test_main(capsys, tmpdir): ] tmpdir.mkdir(".git") - # If no files are passed in the quick guide is returned - main.main(base_args) + # If nothing is passed in the quick guide is returned without erroring + main.main([]) out, error = capsys.readouterr() assert main.QUICK_GUIDE in out assert not error + # If no files are passed in but arguments are the quick guide is returned, alongside an error. + with pytest.raises(SystemExit): + main.main(base_args) + out, error = capsys.readouterr() + assert main.QUICK_GUIDE in out + # Unless the config is requested, in which case it will be returned alone as JSON main.main(base_args + ["--show-config"]) out, error = capsys.readouterr()