Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/docformatter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ def _main(argv, standard_out, standard_error, standard_in):
"""Run internal main entry point."""
configurator = _configuration.Configurater(argv)

if "--help" in configurator.args_lst or "-h" in configurator.args_lst:
# Tokens after the "--" end-of-options marker are file names, not options.
_options = configurator.args_lst
if "--" in _options:
_options = _options[: _options.index("--")]

if "--help" in _options or "-h" in _options:
_help()
return 0
else:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_docformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,29 @@ def test_help_output(self):
)
assert ret_code == 0

@pytest.mark.system
def test_help_flag_after_end_of_options_is_a_path(
self, tmp_path, monkeypatch, capsys
):
"""Treat -h after the -- marker as a path, not as a help request."""
monkeypatch.chdir(tmp_path)
(tmp_path / "-h").mkdir()
(tmp_path / "-h" / "bad.py").write_text(
'def f():\n """ Needs fixing. """\n'
)
stderr = io.StringIO()

ret_code = main._main(
argv=["my_fake_program", "--check", "--recursive", "--", "-h"],
standard_out=io.StringIO(),
standard_error=stderr,
standard_in=None,
)

assert ret_code == 3 # FormatResult.format_required
assert "usage:" not in capsys.readouterr().out
assert stderr.getvalue().strip() == os.path.join("-h", "bad.py")


class TestEndToEnd:
"""Class to test docformatter by executing it from the command line."""
Expand Down
Loading