avoid empty lines if help text is empty
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Krzysztof Kotlenga · committed by David Lord · parent a4f5450 · Browse files · 4 files·+26 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+26 added−16 removed
- tests:+20 added−14 removed
- other:+6 added−2 removed
Provenance
- Commit
589ca31- Tree
43378cc- Author
Krzysztof Kotlenga <k.kotlenga@sims.pl>- Committer
David Lord <davidism@gmail.com>- Parent
a4f5450
4 files changed+26 added−16 removed
modified:src/click/core.py+5 added-2 removed
1358 unmodified lines1359 self.format_epilog(ctx, formatter)1360 1361 def format_help_text(self, ctx: Context, formatter: HelpFormatter) -> None:1362 """Writes the help text to the formatter if it exists."""1363- text = self.help if self.help is not None else ""1363+ if self.help is not None:1364+ # truncate the help text to the first form feed1365+ text = inspect.cleandoc(self.help).partition("\f")[0]1366+ else:1367+ text = ""1368 1369 if self.deprecated:1370 text = _("(Deprecated) {text}").format(text=text)1371 1372 if text:1369- text = inspect.cleandoc(text).partition("\f")[0]1373 formatter.write_paragraph()1374 1375 with formatter.indentation():1376 formatter.write_text(text)1664 unmodified linesmodified:tests/test_commands.py-14 removed
93 unmodified lines94 is not None95 )96 97 98-def test_help_truncation(runner):99- @click.command()100- def cli():101- """This is a command with truncated help.102- \f103-104- This text should be truncated.105- """106-107- result = runner.invoke(cli, ["--help"])108- assert result.exit_code == 0109- assert "This is a command with truncated help." in result.output110-111-98 def test_no_args_is_help(runner):99 @click.command(no_args_is_help=True)100 def cli():101 pass298 unmodified linesmodified:tests/test_formatting.py+20 added
294 unmodified lines295 " --help Show this message and exit.",296 ]297 298 299+def test_truncating_docstring_no_help(runner):300+ @click.command()301+ @click.pass_context302+ def cli(ctx):303+ """304+ \f305+306+ This text should be truncated.307+ """308+309+ result = runner.invoke(cli, ["--help"], terminal_width=60)310+ assert not result.exception311+ assert result.output.splitlines() == [312+ "Usage: cli [OPTIONS]",313+ "",314+ "Options:",315+ " --help Show this message and exit.",316+ ]317+318+319 def test_removing_multiline_marker(runner):320 @click.group()321 def cli():322 pass46 unmodified linesmodified:CHANGES.rst+1 added
14 unmodified lines15 - Completion works if there is a dot (``.``) in the program name. :issue:`2166`16 - Improve type annotations for pyright type checker. :issue:`2268`17 - Improve responsiveness of ``click.clear()``. :issue:`2284`18 - Improve command name detection when using Shiv or PEX. :issue:`2332`19+- Avoid showing empty lines if command help text is empty. :issue:`2368`20 21 22 Version 8.1.323 -------------1040 unmodified lines