Skip to content

Commit

Permalink
account for linebreak in help summary
Browse files Browse the repository at this point in the history
  • Loading branch information
srafi1 authored and amy-lei committed Oct 30, 2020
1 parent 801a29f commit 17a82fc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Unreleased
- Fix formatting when ``Command.options_metavar`` is empty. :pr:`1551`
- The default value passed to ``prompt`` will be cast to the correct
type like an input value would be. :pr:`1517`
- Automatically generated short help messages will stop at the first
ending of a phrase or double linebreak. :issue:`1082`


Version 7.1.2
Expand Down
3 changes: 3 additions & 0 deletions src/click/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def make_str(value):

def make_default_short_help(help, max_length=45):
"""Return a condensed version of help string."""
line_ending = help.find("\n\n")
if line_ending != -1:
help = help[:line_ending]
words = help.split()
total_length = 0
result = []
Expand Down
19 changes: 19 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,22 @@ def nope():
assert result.exit_code == 0
assert "subgroup" not in result.output
assert "nope" not in result.output


def test_summary_line(runner):
@click.group()
def cli():
pass

@cli.command()
def cmd():
"""
Summary line without period
Here is a sentence. And here too.
"""
pass

result = runner.invoke(cli, ["--help"])
assert "Summary line without period" in result.output
assert "Here is a sentence." not in result.output

0 comments on commit 17a82fc

Please sign in to comment.