defer processing Command.help, epilog, and short_help
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 39ee8b0 · Browse files · 2 files·+19 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+19 added−33 removed
- other:+19 added−33 removed
Provenance
- Commit
92b30e4- Tree
c4c10a7- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
39ee8b0
2 files changed+19 added−33 removed
modified:src/click/core.py+14 added-29 removed
1154 unmodified lines1155 :param deprecated: issues a message indicating that1156 the command is deprecated.1157 1158 .. versionchanged:: 8.11159- ``help`` is stored untruncated, the formatter applied1160- truncation later.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 1162- .. versionchanged:: 8.11163- Indentation in ``help`` is cleaned here instead of only in the1164- ``@command`` decorator. ``epilog`` and ``short_help`` are also1165- cleaned.1166-1163 .. versionchanged:: 8.01164 Added a ``repr`` showing the command name.1165 1166 .. versionchanged:: 7.125 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 []1200-1201- if help:1202- help = inspect.cleandoc(help)1203-1204- if epilog:1205- epilog = inspect.cleandoc(epilog)1206-1207- if short_help:1208- short_help = inspect.cleandoc(short_help)1209-1196 self.help = help1197 self.epilog = epilog1198 self.options_metavar = options_metavar1199 self.short_help = short_help5 unmodified lines1205 def to_info_dict(self, ctx: Context) -> t.Dict[str, t.Any]:1206 info_dict = super().to_info_dict(ctx)1207 info_dict.update(1208 params=[param.to_info_dict() for param in self.get_params(ctx)],1223- # truncate help text to the content preceding the first form feed,1224- # if any1225- help=self.help.split("\f", 1)[0] if self.help else self.help,1209+ help=self.help,1210 epilog=self.epilog,1211 short_help=self.short_help,1212 hidden=self.hidden,1213 deprecated=self.deprecated,85 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 1350- # truncate the help text to the content preceding the first form feed,1351- # if any1352- text = text.split("\f", 1)[0]1353-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():1380- 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:CHANGES.rst+5 added-4 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 untruncated help string in ``Command.help``, and perform37- truncation when formatting. :issue:`2149`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