summaryrefslogtreecommitdiff
path: root/src/click/core.py
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2022-02-21 10:02:12 -0800
committerDavid Lord <davidism@gmail.com>2022-02-21 10:02:12 -0800
commit92b30e47cb013433190f40d75239c98c77aa9d2d (patch)
treec4c10a7f1c3a08e6e41c2d9ee21a26769cc65372 /src/click/core.py
parent39ee8b0580ee48c43801feaa0c9a5b454a3e0e19 (diff)
downloadclick-92b30e47cb013433190f40d75239c98c77aa9d2d.tar.gz
defer processing Command.help, epilog, and short_help
Diffstat (limited to 'src/click/core.py')
-rw-r--r--src/click/core.py43
1 files changed, 14 insertions, 29 deletions
diff --git a/src/click/core.py b/src/click/core.py
index 95a4761..9ba738b 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -1156,13 +1156,9 @@ class Command(BaseCommand):
the command is deprecated.
.. versionchanged:: 8.1
- ``help`` is stored untruncated, the formatter applied
- truncation later.
-
- .. versionchanged:: 8.1
- Indentation in ``help`` is cleaned here instead of only in the
- ``@command`` decorator. ``epilog`` and ``short_help`` are also
- cleaned.
+ ``help``, ``epilog``, and ``short_help`` are stored unprocessed,
+ all formatting is done when outputting help text, not at init,
+ and is done even if not using the ``@command`` decorator.
.. versionchanged:: 8.0
Added a ``repr`` showing the command name.
@@ -1197,16 +1193,6 @@ class Command(BaseCommand):
#: should show up in the help page and execute. Eager parameters
#: will automatically be handled before non eager ones.
self.params: t.List["Parameter"] = params or []
-
- if help:
- help = inspect.cleandoc(help)
-
- if epilog:
- epilog = inspect.cleandoc(epilog)
-
- if short_help:
- short_help = inspect.cleandoc(short_help)
-
self.help = help
self.epilog = epilog
self.options_metavar = options_metavar
@@ -1220,9 +1206,7 @@ class Command(BaseCommand):
info_dict = super().to_info_dict(ctx)
info_dict.update(
params=[param.to_info_dict() for param in self.get_params(ctx)],
- # truncate help text to the content preceding the first form feed,
- # if any
- help=self.help.split("\f", 1)[0] if self.help else self.help,
+ help=self.help,
epilog=self.epilog,
short_help=self.short_help,
hidden=self.hidden,
@@ -1316,10 +1300,12 @@ class Command(BaseCommand):
"""Gets short help for the command or makes it by shortening the
long help string.
"""
- text = self.short_help or ""
-
- if not text and self.help:
+ if self.short_help:
+ text = inspect.cleandoc(self.short_help)
+ elif self.help:
text = make_default_short_help(self.help, limit)
+ else:
+ text = ""
if self.deprecated:
text = _("(Deprecated) {text}").format(text=text)
@@ -1345,16 +1331,13 @@ class Command(BaseCommand):
def format_help_text(self, ctx: Context, formatter: HelpFormatter) -> None:
"""Writes the help text to the formatter if it exists."""
- text = self.help or ""
-
- # truncate the help text to the content preceding the first form feed,
- # if any
- text = text.split("\f", 1)[0]
+ text = self.help if self.help is not None else ""
if self.deprecated:
text = _("(Deprecated) {text}").format(text=text)
if text:
+ text = inspect.cleandoc(text).partition("\f")[0]
formatter.write_paragraph()
with formatter.indentation():
@@ -1375,9 +1358,11 @@ class Command(BaseCommand):
def format_epilog(self, ctx: Context, formatter: HelpFormatter) -> None:
"""Writes the epilog into the formatter if it exists."""
if self.epilog:
+ epilog = inspect.cleandoc(self.epilog)
formatter.write_paragraph()
+
with formatter.indentation():
- formatter.write_text(self.epilog)
+ formatter.write_text(epilog)
def parse_args(self, ctx: Context, args: t.List[str]) -> t.List[str]:
if not args and self.no_args_is_help and not ctx.resilient_parsing: