Skip to content
Myr

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

2 files+19 added−33 removed

modified:src/click/core.py+14 added-29 removed
1154 unmodified lines
1155 :param deprecated: issues a message indicating that1156 the command is deprecated.11571158 .. 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.11621162 .. versionchanged:: 8.11163 Indentation in ``help`` is cleaned here instead of only in the1164 ``@command`` decorator. ``epilog`` and ``short_help`` are also1165 cleaned.11661163 .. versionchanged:: 8.01164 Added a ``repr`` showing the command name.11651166 .. versionchanged:: 7.1
25 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 []12001201 if help:1202 help = inspect.cleandoc(help)12031204 if epilog:1205 epilog = inspect.cleandoc(epilog)12061207 if short_help:1208 short_help = inspect.cleandoc(short_help)12091196 self.help = help1197 self.epilog = epilog1198 self.options_metavar = options_metavar1199 self.short_help = short_help
5 unmodified lines
1205 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 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 ""13351350 # truncate the help text to the content preceding the first form feed,1351 # if any1352 text = text.split("\f", 1)[0]13531336 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():1380 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:CHANGES.rst+5 added-4 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 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`394041Version 8.0.442-------------
948 unmodified lines