cleandoc for 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 2c70a0c · Browse files · 3 files·+34 added−20 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+34 added−20 removed
- other:+34 added−20 removed
Provenance
- Commit
721c8b0- Tree
f0ab885- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
2c70a0c
3 files changed+34 added−20 removed
modified:src/click/core.py+28 added-11 removed
1131 unmodified lines1132 """Commands are the basic building block of command line interfaces in1133 Click. A basic command handles command line parsing and might dispatch1134 more parsing to commands nested below it.1135 1136- .. versionchanged:: 2.01137- Added the `context_settings` parameter.1138- .. versionchanged:: 8.01139- Added repr showing the command name1140- .. versionchanged:: 7.11141- Added the `no_args_is_help` parameter.1142-1136 :param name: the name of the command to use unless a group overrides it.1137 :param context_settings: an optional dictionary with defaults that are1138 passed to the context object.1139 :param callback: the callback to invoke. This is optional.13 unmodified lines1153 :param hidden: hide this command from help outputs.1154 1155 :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.1162+1163+ .. versionchanged:: 8.01164+ Added a ``repr`` showing the command name.1165+1166+ .. versionchanged:: 7.11167+ Added the ``no_args_is_help`` parameter.1168+1169+ .. versionchanged:: 2.01170+ Added the ``context_settings`` parameter.1171 """1172 1173 def __init__(1174 self,18 unmodified lines1193 #: 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 1190- # if a form feed (page break) is found in the help text, truncate help1191- # text to the content preceding the first form feed1192- if help and "\f" in help:1193- help = help.split("\f", 1)[0]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+1212 self.help = help1213 self.epilog = epilog1214 self.options_metavar = options_metavar1215 self.short_help = short_help1759 unmodified linesmodified:src/click/decorators.py+2 added-7 removed
135 unmodified lines136 del f.__click_params__ # type: ignore137 except AttributeError:138 params = []139 140- help = attrs.get("help")140+ if attrs.get("help") is None:141+ attrs["help"] = inspect.getdoc(f)142 142- if help is None:143- help = inspect.getdoc(f)144- else:145- help = inspect.cleandoc(help)146-147- attrs["help"] = help143 return cls(144 name=name or f.__name__.lower().replace("_", "-"),145 callback=f,146 params=params,339 unmodified linesmodified:CHANGES.rst+4 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-- Help text passed to ``Option`` is processed the same way as using31- the ``@option`` decorator. :issue:`1985`30+- Indentation in help text passed to ``Option`` and ``Command`` is31+ cleaned the same as using the ``@option`` and ``@command``32+ decorators does. A command's ``epilog`` and ``short_help`` are also33+ processed. :issue:`1985`34 35 36 Version 8.0.437 -------------948 unmodified lines