Skip to content

Commit

Permalink
Fixed #1356: return status when arguments are passed in without files…
Browse files Browse the repository at this point in the history
… or a content stream.
  • Loading branch information
timothycrosley committed Jul 30, 2020
1 parent b8c8c00 commit 39adcee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 39adcee

Please sign in to comment.