Skip to content
Myr

Improved automatic short help detection. This fixes #165

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent f1a8460 · Browse files · 3 files+10 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+10 added−3 removed

  • tests:+7 added−1 removed
  • other:+3 added−2 removed

3 files+10 added−3 removed

modified:click/utils.py+1 added-2 removed
101 unmodified lines
102 result = []103 done = False104105 for word in words:106 if '.' in word:107 word = word.split('.', 1)[0] + '.'106 if word[-1:] == '.':107 done = True108 new_length = result and 1 + len(word) or len(word)109 if total_length + new_length > max_length:110 result.append('...')
251 unmodified lines
modified:tests/test_commands.py+7 added-1 removed
47 unmodified lines
48 def short():49 """This is a short text."""5051 @cli.command()52 def special_chars():53 """Login and store the token in ~/.netrc."""5455 @cli.command()56 def long():57 """This is a long text that is too long to show as short help58 and will be truncated instead."""5960 result = runner.invoke(cli, ['--help'])61 assert re.search(62 r'Commands:\n\s+'63 r'long\s+This is a long text that is too long to show\.\.\.\n\s+'60 r'short\s+This is a short text\.', result.output) is not None64 r'short\s+This is a short text\.\n\s+'65 r'special_chars\s+Login and store the token in ~/.netrc\.\s*',66 result.output) is not None676869def test_default_maps(runner):70 @click.group()
106 unmodified lines
modified:CHANGES+2 added
13 unmodified lines
14- added a way to not swallow exceptions in the test system.15- added better support for colors with pagers and ways to16 override the autodetection.17- the CLI runner's result object now has a traceback attached.18- improved automatic short help detection to work better with19 dots that do not terminate sentences.2021Version 2.122-----------23
69 unmodified lines