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
Provenance
- Commit
c01e2b8- Tree
c4c10a7- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
4262661- Parent 2
92b30e4
3 files changed+32 added−26 removed
modified:src/click/core.py+13 added-24 removed
1154 unmodified lines1155 :param deprecated: issues a message indicating that1156 the command is deprecated.1157 1158 .. 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.1162 1163 .. versionchanged:: 8.01164 Added a ``repr`` showing the command name.1165 26 unmodified lines1192 #: 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 []1196-1197- if help:1198- help = inspect.cleandoc(help)1199-1200- # 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]1205-1206- if epilog:1207- epilog = inspect.cleandoc(epilog)1208-1209- if short_help:1210- short_help = inspect.cleandoc(short_help)1211-1196 self.help = help1197 self.epilog = epilog1198 self.options_metavar = options_metavar1199 self.short_help = short_help99 unmodified lines1299 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 ""1320-1321- 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 = ""1309 1310 if self.deprecated:1311 text = _("(Deprecated) {text}").format(text=text)1312 17 unmodified lines1330 self.format_epilog(ctx, formatter)1331 1332 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 ""1335 1336 if self.deprecated:1337 text = _("(Deprecated) {text}").format(text=text)1338 1339 if text:1340+ text = inspect.cleandoc(text).partition("\f")[0]1341 formatter.write_paragraph()1342 1343 with formatter.indentation():1344 formatter.write_text(text)12 unmodified lines1357 1358 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()1363+1364 with formatter.indentation():1376- formatter.write_text(self.epilog)1365+ formatter.write_text(epilog)1366 1367 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 linesmodified:tests/test_commands.py+14 added
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+112 def test_no_args_is_help(runner):113 @click.command(no_args_is_help=True)114 def cli():115 pass239 unmodified linesmodified:CHANGES.rst+5 added-2 removed
25 unmodified lines26 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`39 40 41 Version 8.0.442 -------------948 unmodified lines