diff options
author | Gianluca Gippetto <gianluca.gippetto@gmail.com> | 2021-07-04 16:31:06 +0200 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2022-02-20 10:40:38 -0800 |
commit | 2c70a0c15a3c154c587e351062be66bb75cbf3f2 (patch) | |
tree | 845f18371db3bba5139cb961bceabd3c1ce9ac06 | |
parent | c9c406bebdf2b027864216fb881278a8bfa14bb8 (diff) | |
download | click-2c70a0c15a3c154c587e351062be66bb75cbf3f2.tar.gz |
Option calls cleandoc on help instead of @option
-rw-r--r-- | CHANGES.rst | 2 | ||||
-rw-r--r-- | src/click/core.py | 7 | ||||
-rw-r--r-- | src/click/decorators.py | 3 |
3 files changed, 9 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index c11361c..98ea518 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,6 +27,8 @@ Version 8.1.0 - Parameter decorators and ``@group`` handles ``cls=None`` the same as not passing ``cls``. ``@option`` handles ``help=None`` the same as not passing ``help``. :issue:`#1959` +- Help text passed to ``Option`` is processed the same way as using + the ``@option`` decorator. :issue:`1985` Version 8.0.4 diff --git a/src/click/core.py b/src/click/core.py index 604d8ba..59af7ce 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -2416,6 +2416,10 @@ class Option(Parameter): :param hidden: hide this option from help outputs. .. versionchanged:: 8.1.0 + Help text indentation is cleaned here instead of only in the + ``@option`` decorator. + + .. versionchanged:: 8.1.0 The ``show_default`` parameter overrides ``Context.show_default``. @@ -2449,6 +2453,9 @@ class Option(Parameter): show_envvar: bool = False, **attrs: t.Any, ) -> None: + if help: + help = inspect.cleandoc(help) + default_is_missing = "default" not in attrs super().__init__(param_decls, type=type, multiple=multiple, **attrs) diff --git a/src/click/decorators.py b/src/click/decorators.py index a2fbadd..4c00e9d 100644 --- a/src/click/decorators.py +++ b/src/click/decorators.py @@ -297,9 +297,6 @@ def option(*param_decls: str, **attrs: t.Any) -> t.Callable[[FC], FC]: def decorator(f: FC) -> FC: # Issue 926, copy attrs, so pre-defined options can re-use the same cls= option_attrs = attrs.copy() - - if option_attrs.get("help"): - option_attrs["help"] = inspect.cleandoc(option_attrs["help"]) OptionClass = option_attrs.pop("cls", None) or Option _param_memo(f, OptionClass(param_decls, **option_attrs)) return f |