Merge pull request #1987 from janluke/fix/option-help-processing
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Move processing of `help` from `@option` into `Option`
authored by David Lord · committed by GitHub · parents c9c406b, 721c8b0 · Browse files · 3 files·+41 added−21 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+41 added−21 removed
- other:+41 added−21 removed
Provenance
- Commit
22d3886- Tree
f0ab885- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
c9c406b- Parent 2
721c8b0
3 files changed+41 added−21 removed
modified:src/click/core.py+35 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_help1216 unmodified lines2432 :param help: the help string.2433 :param hidden: hide this option from help outputs.2434 2435 .. versionchanged:: 8.1.02436+ Help text indentation is cleaned here instead of only in the2437+ ``@option`` decorator.2438+2439+ .. versionchanged:: 8.1.02440 The ``show_default`` parameter overrides2441 ``Context.show_default``.2442 2443 .. versionchanged:: 8.1.025 unmodified lines2469 show_choices: bool = True,2470 show_envvar: bool = False,2471 **attrs: t.Any,2472 ) -> None:2473+ if help:2474+ help = inspect.cleandoc(help)2475+2476 default_is_missing = "default" not in attrs2477 super().__init__(param_decls, type=type, multiple=multiple, **attrs)2478 2479 if prompt is True:495 unmodified linesmodified:src/click/decorators.py+2 added-10 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,144 unmodified lines291 292 def decorator(f: FC) -> FC:293 # Issue 926, copy attrs, so pre-defined options can re-use the same cls=294 option_attrs = attrs.copy()300-301- if option_attrs.get("help"):302- option_attrs["help"] = inspect.cleandoc(option_attrs["help"])295 OptionClass = option_attrs.pop("cls", None) or Option296 _param_memo(f, OptionClass(param_decls, **option_attrs))297 return f298 187 unmodified linesmodified:CHANGES.rst+4 added
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+- 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