diff options
author | Stephen Finucane <stephen@that.guru> | 2021-12-08 17:09:27 +0000 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2022-02-20 12:04:07 -0800 |
commit | 39ee8b0580ee48c43801feaa0c9a5b454a3e0e19 (patch) | |
tree | 9e84c8330d8d2e2230d3bfeffd3592937ba7cd31 /src | |
parent | 4262661a0fffabe3803f1bd876b19244f587dafa (diff) | |
download | click-39ee8b0580ee48c43801feaa0c9a5b454a3e0e19.tar.gz |
Store raw help string for commands
Some tools, such as sphinx-click [1], may wish to access the full help
string for a command including any text after the form feed character
(which indicates truncation [2]). Make this possible by storing the
help string without truncation and instead truncate when we use this
string (i.e. truncate on load, not on store).
[1] https://github.com/click-contrib/sphinx-click/issues/56
[2] https://click.palletsprojects.com/en/latest/documentation/#truncating-help-texts
Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'src')
-rw-r--r-- | src/click/core.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/click/core.py b/src/click/core.py index 1ab2b20..95a4761 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -1156,6 +1156,10 @@ 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. @@ -1197,12 +1201,6 @@ class Command(BaseCommand): if help: help = inspect.cleandoc(help) - # Discard help text after a first form feed (page break) - # character, to allow writing longer documentation in - # docstrings that does not show in help output. - if "\f" in help: - help = help.partition("\f")[0] - if epilog: epilog = inspect.cleandoc(epilog) @@ -1222,7 +1220,9 @@ 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)], - help=self.help, + # 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, epilog=self.epilog, short_help=self.short_help, hidden=self.hidden, @@ -1347,6 +1347,10 @@ class Command(BaseCommand): """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] + if self.deprecated: text = _("(Deprecated) {text}").format(text=text) |