Skip to content
Myr

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

3 files+41 added−21 removed

modified:src/click/core.py+35 added-11 removed
1131 unmodified lines
1132 """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.11351136 .. 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.11421136 :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 lines
1153 :param hidden: hide this command from help outputs.11541155 :param deprecated: issues a message indicating that1156 the command is deprecated.11571158 .. versionchanged:: 8.11159 Indentation in ``help`` is cleaned here instead of only in the1160 ``@command`` decorator. ``epilog`` and ``short_help`` are also1161 cleaned.11621163 .. versionchanged:: 8.01164 Added a ``repr`` showing the command name.11651166 .. versionchanged:: 7.11167 Added the ``no_args_is_help`` parameter.11681169 .. versionchanged:: 2.01170 Added the ``context_settings`` parameter.1171 """11721173 def __init__(1174 self,
18 unmodified lines
1193 #: 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 []11961190 # 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)11991200 # 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]12051206 if epilog:1207 epilog = inspect.cleandoc(epilog)12081209 if short_help:1210 short_help = inspect.cleandoc(short_help)12111212 self.help = help1213 self.epilog = epilog1214 self.options_metavar = options_metavar1215 self.short_help = short_help
1216 unmodified lines
2432 :param help: the help string.2433 :param hidden: hide this option from help outputs.24342435 .. versionchanged:: 8.1.02436 Help text indentation is cleaned here instead of only in the2437 ``@option`` decorator.24382439 .. versionchanged:: 8.1.02440 The ``show_default`` parameter overrides2441 ``Context.show_default``.24422443 .. versionchanged:: 8.1.0
25 unmodified lines
2469 show_choices: bool = True,2470 show_envvar: bool = False,2471 **attrs: t.Any,2472 ) -> None:2473 if help:2474 help = inspect.cleandoc(help)24752476 default_is_missing = "default" not in attrs2477 super().__init__(param_decls, type=type, multiple=multiple, **attrs)24782479 if prompt is True:
495 unmodified lines
modified:src/click/decorators.py+2 added-10 removed
135 unmodified lines
136 del f.__click_params__ # type: ignore137 except AttributeError:138 params = []139140 help = attrs.get("help")140 if attrs.get("help") is None:141 attrs["help"] = inspect.getdoc(f)142142 if help is None:143 help = inspect.getdoc(f)144 else:145 help = inspect.cleandoc(help)146147 attrs["help"] = help143 return cls(144 name=name or f.__name__.lower().replace("_", "-"),145 callback=f,146 params=params,
144 unmodified lines
291292 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()300301 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 lines
modified:CHANGES.rst+4 added
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- 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`343536Version 8.0.437-------------
948 unmodified lines