Skip to content
Myr

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

4 files+26 added−16 removed

modified:src/click/core.py+5 added-2 removed
1358 unmodified lines
1359 self.format_epilog(ctx, formatter)13601361 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 = ""13681369 if self.deprecated:1370 text = _("(Deprecated) {text}").format(text=text)13711372 if text:1369 text = inspect.cleandoc(text).partition("\f")[0]1373 formatter.write_paragraph()13741375 with formatter.indentation():1376 formatter.write_text(text)
1664 unmodified lines
modified:tests/test_commands.py-14 removed
93 unmodified lines
94 is not None95 )969798def test_help_truncation(runner):99 @click.command()100 def cli():101 """This is a command with truncated help.102 \f103104 This text should be truncated.105 """106107 result = runner.invoke(cli, ["--help"])108 assert result.exit_code == 0109 assert "This is a command with truncated help." in result.output11011198def test_no_args_is_help(runner):99 @click.command(no_args_is_help=True)100 def cli():101 pass
298 unmodified lines
modified:tests/test_formatting.py+20 added
294 unmodified lines
295 " --help Show this message and exit.",296 ]297298299def test_truncating_docstring_no_help(runner):300 @click.command()301 @click.pass_context302 def cli(ctx):303 """304 \f305306 This text should be truncated.307 """308309 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 ]317318319def test_removing_multiline_marker(runner):320 @click.group()321 def cli():322 pass
46 unmodified lines
modified:CHANGES.rst+1 added
14 unmodified lines
15- 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`202122Version 8.1.323-------------
1040 unmodified lines