summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2022-02-21 20:06:24 -0800
committerDavid Lord <davidism@gmail.com>2022-02-21 20:06:24 -0800
commit46b78bcb80ac4f81e3248a83725c6f0adcc1089a (patch)
treef50dc47bb8b90d26b9a3bc3509444244c7f99e5c /src
parentf6a681adc13d5961073c00e57044e3855c3b76bd (diff)
downloadclick-46b78bcb80ac4f81e3248a83725c6f0adcc1089a.tar.gz
command decorator params argument
Diffstat (limited to 'src')
-rw-r--r--src/click/decorators.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/click/decorators.py b/src/click/decorators.py
index ca86094..d7b1724 100644
--- a/src/click/decorators.py
+++ b/src/click/decorators.py
@@ -153,6 +153,8 @@ def command(
pass the intended name as the first argument.
All keyword arguments are forwarded to the underlying command class.
+ For the ``params`` argument, any decorated params are appended to
+ the end of the list.
Once decorated the function turns into a :class:`Command` instance
that can be invoked as a command line utility or be attached to a
@@ -165,6 +167,10 @@ def command(
.. versionchanged:: 8.1
This decorator can be applied without parentheses.
+
+ .. versionchanged:: 8.1
+ The ``params`` argument can be used. Decorated params are
+ appended to the end of the list.
"""
if cls is None:
cls = Command
@@ -179,13 +185,16 @@ def command(
if isinstance(f, Command):
raise TypeError("Attempted to convert a callback into a command twice.")
+ attr_params = attrs.pop("params", None)
+ params = attr_params if attr_params is not None else []
+
try:
- params = f.__click_params__ # type: ignore
+ decorator_params = f.__click_params__ # type: ignore
except AttributeError:
- params = []
+ pass
else:
- params.reverse()
del f.__click_params__ # type: ignore
+ params.extend(reversed(decorator_params))
if attrs.get("help") is None:
attrs["help"] = f.__doc__