Skip to content

Commit

Permalink
fix: handle 3+ word Options: section names
Browse files Browse the repository at this point in the history
parse_defaults() was failing with an AssertionError when an options
section with 3 or more words was used. e.g. "Very Advanced Options:".

This fixes #9
  • Loading branch information
h4l committed Sep 8, 2022
1 parent 57dd340 commit c817b29
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 1 addition & 3 deletions docopt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,7 @@ def parse_defaults(docstring: str) -> list[Option]:
defaults = []
for s in parse_section("options:", docstring):
options_literal, _, s = s.partition(":")
if " " in options_literal:
_, _, options_literal = options_literal.partition(" ")
assert options_literal.lower().strip() == "options"
assert options_literal.lower().endswith("options")
split = re.split(r"\n[ \t]*(-\S+?)", "\n" + s)[1:]
split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])]
for s in split:
Expand Down
1 change: 1 addition & 0 deletions tests/test_docopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ def test_language_errors():
[
pytest.param("Usage: prog\n Options: --foo\n"),
pytest.param("Usage: prog\n Advanced Options: --foo\n"),
pytest.param("Usage: prog\n Very Advanced Options: --foo\n"),
],
)
def test_docopt_reports_options_in_usage_section(doc: str):
Expand Down

0 comments on commit c817b29

Please sign in to comment.