Skip to content
Myr

Merge pull request #2151 from stephenfin/store-untruncated-help

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

Store raw help string for commands

authored by David Lord · committed by GitHub · parents 4262661, 92b30e4 · Browse files · 3 files+32 added−26 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+32 added−26 removed

  • tests:+14 added−0 removed
  • other:+18 added−26 removed

3 files+32 added−26 removed

modified:src/click/core.py+13 added-24 removed
1154 unmodified lines
1155 :param deprecated: issues a message indicating that1156 the command is deprecated.11571158 .. versionchanged:: 8.11159 Indentation in ``help`` is cleaned here instead of only in the1160 ``@command`` decorator. ``epilog`` and ``short_help`` are also1161 cleaned.1159 ``help``, ``epilog``, and ``short_help`` are stored unprocessed,1160 all formatting is done when outputting help text, not at init,1161 and is done even if not using the ``@command`` decorator.11621163 .. versionchanged:: 8.01164 Added a ``repr`` showing the command name.1165
26 unmodified lines
1192 #: the list of parameters for this command in the order they1193 #: should show up in the help page and execute. Eager parameters1194 #: will automatically be handled before non eager ones.1195 self.params: t.List["Parameter"] = params or []11961197 if help:1198 help = inspect.cleandoc(help)11991200 # Discard help text after a first form feed (page break)1201 # character, to allow writing longer documentation in1202 # docstrings that does not show in help output.1203 if "\f" in help:1204 help = help.partition("\f")[0]12051206 if epilog:1207 epilog = inspect.cleandoc(epilog)12081209 if short_help:1210 short_help = inspect.cleandoc(short_help)12111196 self.help = help1197 self.epilog = epilog1198 self.options_metavar = options_metavar1199 self.short_help = short_help
99 unmodified lines
1299 def get_short_help_str(self, limit: int = 45) -> str:1300 """Gets short help for the command or makes it by shortening the1301 long help string.1302 """1319 text = self.short_help or ""13201321 if not text and self.help:1303 if self.short_help:1304 text = inspect.cleandoc(self.short_help)1305 elif self.help:1306 text = make_default_short_help(self.help, limit)1307 else:1308 text = ""13091310 if self.deprecated:1311 text = _("(Deprecated) {text}").format(text=text)1312
17 unmodified lines
1330 self.format_epilog(ctx, formatter)13311332 def format_help_text(self, ctx: Context, formatter: HelpFormatter) -> None:1333 """Writes the help text to the formatter if it exists."""1348 text = self.help or ""1334 text = self.help if self.help is not None else ""13351336 if self.deprecated:1337 text = _("(Deprecated) {text}").format(text=text)13381339 if text:1340 text = inspect.cleandoc(text).partition("\f")[0]1341 formatter.write_paragraph()13421343 with formatter.indentation():1344 formatter.write_text(text)
12 unmodified lines
13571358 def format_epilog(self, ctx: Context, formatter: HelpFormatter) -> None:1359 """Writes the epilog into the formatter if it exists."""1360 if self.epilog:1361 epilog = inspect.cleandoc(self.epilog)1362 formatter.write_paragraph()13631364 with formatter.indentation():1376 formatter.write_text(self.epilog)1365 formatter.write_text(epilog)13661367 def parse_args(self, ctx: Context, args: t.List[str]) -> t.List[str]:1368 if not args and self.no_args_is_help and not ctx.resilient_parsing:1369 echo(ctx.get_help(), color=ctx.color)
1594 unmodified lines
modified:tests/test_commands.py+14 added
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.output110111112def test_no_args_is_help(runner):113 @click.command(no_args_is_help=True)114 def cli():115 pass
239 unmodified lines
modified:CHANGES.rst+5 added-2 removed
25 unmodified lines
26 of the other way around. :issue:`1963`27- Parameter decorators and ``@group`` handles ``cls=None`` the same as28 not passing ``cls``. ``@option`` handles ``help=None`` the same as29 not passing ``help``. :issue:`#1959`30- A flag option with ``required=True`` requires that the flag is31 passed instead of choosing the implicit default value. :issue:`1978`32- Indentation in help text passed to ``Option`` and ``Command`` is33 cleaned the same as using the ``@option`` and ``@command``34 decorators does. A command's ``epilog`` and ``short_help`` are also35 processed. :issue:`1985`34- A flag option with ``required=True`` requires that the flag is35 passed instead of choosing the implicit default value. :issue:`1978`36- Store unprocessed ``Command.help``, ``epilog`` and ``short_help``37 strings. Processing is only done when formatting help text for38 output. :issue:`2149`394041Version 8.0.442-------------
948 unmodified lines