We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Automatically dedent help text of options?
```
import click

@click.command()
@click.option('--foo', help="""
    heyho

    i am

    multiline
""")
def cli(foo):
    click.echo(foo)

cli()
```

This currently does not remove the leading whitespace from each paragraph in the help text for `--foo`:

```
untitaker@untibox:~/projects/click, branch master
$ python lol.py --help
Usage: lol.py [OPTIONS]

Options:
  --foo TEXT
                  heyho

                  i am

                  multiline
  --help      Show this message and exit.
```

Although i am not sure if help texts for options are even supposed to get that
complex.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `click/decorators.py`
Content:
```
1 import sys
2 import inspect
3 
4 from functools import update_wrapper
5 
6 from ._compat import iteritems
7 from .utils import echo
8 
9 
10 def pass_context(f):
11     """Marks a callback as wanting to receive the current context
12     object as first argument.
13     """
14     f.__click_pass_context__ = True
15     return f
16 
17 
18 def pass_obj(f):
19     """Similar to :func:`pass_context`, but only pass the object on the
20     context onwards (:attr:`Context.obj`).  This is useful if that object
21     represents the state of a nested system.
22     """
23     @pass_context
24     def new_func(*args, **kwargs):
25         ctx = args[0]
26         return ctx.invoke(f, ctx.obj, *args[1:], **kwargs)
27     return update_wrapper(new_func, f)
28 
29 
30 def make_pass_decorator(object_type, ensure=False):
31     """Given an object type this creates a decorator that will work
32     similar to :func:`pass_obj` but instead of passing the object of the
33     current context, it will find the innermost context of type
34     :func:`object_type`.
35 
36     This generates a decorator that works roughly like this::
37 
38         from functools import update_wrapper
39 
40         def decorator(f):
41             @pass_context
42             def new_func(ctx, *args, **kwargs):
43                 obj = ctx.find_object(object_type)
44                 return ctx.invoke(f, obj, *args, **kwargs)
45             return update_wrapper(new_func, f)
46         return decorator
47 
48     :param object_type: the type of the object to pass.
49     :param ensure: if set to `True`, a new object will be created and
50                    remembered on the context if it's not there yet.
51     """
52     def decorator(f):
53         @pass_context
54         def new_func(*args, **kwargs):
55             ctx = args[0]
56             if ensure:
57                 obj = ctx.ensure_object(object_type)
58             else:
59                 obj = ctx.find_object(object_type)
60             if obj is None:
61                 raise RuntimeError('Managed to invoke callback without a '
62                                    'context object of type %r existing'
63                                    % object_type.__name__)
64             return ctx.invoke(f, obj, *args[1:], **kwargs)
65         return update_wrapper(new_func, f)
66     return decorator
67 
68 
69 def _make_command(f, name, attrs, cls):
70     if isinstance(f, Command):
71         raise TypeError('Attempted to convert a callback into a '
72                         'command twice.')
73     try:
74         params = f.__click_params__
75         params.reverse()
76         del f.__click_params__
77     except AttributeError:
78         params = []
79     help = inspect.getdoc(f)
80     if isinstance(help, bytes):
81         help = help.decode('utf-8')
82     attrs.setdefault('help', help)
83     return cls(name=name or f.__name__.lower(),
84                callback=f, params=params, **attrs)
85 
86 
87 def command(name=None, cls=None, **attrs):
88     """Creates a new :class:`Command` and uses the decorated function as
89     callback.  This will also automatically attach all decorated
90     :func:`option`\s and :func:`argument`\s as parameters to the command.
91 
92     The name of the command defaults to the name of the function.  If you
93     want to change that, you can pass the intended name as the first
94     argument.
95 
96     All keyword arguments are forwarded to the underlying command class.
97 
98     Once decorated the function turns into a :class:`Command` instance
99     that can be invoked as a command line utility or be attached to a
100     command :class:`Group`.
101 
102     :param name: the name of the command.  This defaults to the function
103                  name.
104     :param cls: the command class to instantiate.  This defaults to
105                 :class:`Command`.
106     """
107     if cls is None:
108         cls = Command
109     def decorator(f):
110         return _make_command(f, name, attrs, cls)
111     return decorator
112 
113 
114 def group(name=None, **attrs):
115     """Creates a new :class:`Group` with a function as callback.  This
116     works otherwise the same as :func:`command` just that the `cls`
117     parameter is set to :class:`Group`.
118     """
119     attrs.setdefault('cls', Group)
120     return command(name, **attrs)
121 
122 
123 def _param_memo(f, param):
124     if isinstance(f, Command):
125         f.params.append(param)
126     else:
127         if not hasattr(f, '__click_params__'):
128             f.__click_params__ = []
129         f.__click_params__.append(param)
130 
131 
132 def argument(*param_decls, **attrs):
133     """Attaches an option to the command.  All positional arguments are
134     passed as parameter declarations to :class:`Argument`; all keyword
135     arguments are forwarded unchanged.  This is equivalent to creating an
136     :class:`Option` instance manually and attaching it to the
137     :attr:`Command.params` list.
138     """
139     def decorator(f):
140         _param_memo(f, Argument(param_decls, **attrs))
141         return f
142     return decorator
143 
144 
145 def option(*param_decls, **attrs):
146     """Attaches an option to the command.  All positional arguments are
147     passed as parameter declarations to :class:`Option`; all keyword
148     arguments are forwarded unchanged.  This is equivalent to creating an
149     :class:`Option` instance manually and attaching it to the
150     :attr:`Command.params` list.
151     """
152     def decorator(f):
153         _param_memo(f, Option(param_decls, **attrs))
154         return f
155     return decorator
156 
157 
158 def confirmation_option(*param_decls, **attrs):
159     """Shortcut for confirmation prompts that can be ignored by passing
160     ``--yes`` as parameter.
161 
162     This is equivalent to decorating a function with :func:`option` with
163     the following parameters::
164 
165         def callback(ctx, param, value):
166             if not value:
167                 ctx.abort()
168 
169         @click.command()
170         @click.option('--yes', is_flag=True, callback=callback,
171                       expose_value=False, prompt='Do you want to continue?')
172         def dropdb():
173             pass
174     """
175     def decorator(f):
176         def callback(ctx, param, value):
177             if not value:
178                 ctx.abort()
179         attrs.setdefault('is_flag', True)
180         attrs.setdefault('callback', callback)
181         attrs.setdefault('expose_value', False)
182         attrs.setdefault('prompt', 'Do you want to continue?')
183         attrs.setdefault('help', 'Confirm the action without prompting.')
184         return option(*(param_decls or ('--yes',)), **attrs)(f)
185     return decorator
186 
187 
188 def password_option(*param_decls, **attrs):
189     """Shortcut for password prompts.
190 
191     This is equivalent to decorating a function with :func:`option` with
192     the following parameters::
193 
194         @click.command()
195         @click.option('--password', prompt=True, confirmation_prompt=True,
196                       hide_input=True)
197         def changeadmin(password):
198             pass
199     """
200     def decorator(f):
201         attrs.setdefault('prompt', True)
202         attrs.setdefault('confirmation_prompt', True)
203         attrs.setdefault('hide_input', True)
204         return option(*(param_decls or ('--password',)), **attrs)(f)
205     return decorator
206 
207 
208 def version_option(version=None, *param_decls, **attrs):
209     """Adds a ``--version`` option which immediately ends the program
210     printing out the version number.  This is implemented as an eager
211     option that prints the version and exits the program in the callback.
212 
213     :param version: the version number to show.  If not provided click
214                     attempts an auto discovery via setuptools.
215     :param prog_name: the name of the program (defaults to autodetection)
216     :param message: custom message to show instead of the default
217                     (``'%(prog)s, version %(version)s'``)
218     :param others: everything else is forwarded to :func:`option`.
219     """
220     if version is None:
221         module = sys._getframe(1).f_globals.get('__name__')
222     def decorator(f):
223         prog_name = attrs.pop('prog_name', None)
224         message = attrs.pop('message', '%(prog)s, version %(version)s')
225 
226         def callback(ctx, param, value):
227             if not value or ctx.resilient_parsing:
228                 return
229             prog = prog_name
230             if prog is None:
231                 prog = ctx.find_root().info_name
232             ver = version
233             if ver is None:
234                 try:
235                     import pkg_resources
236                 except ImportError:
237                     pass
238                 else:
239                     for dist in pkg_resources.working_set:
240                         scripts = dist.get_entry_map().get('console_scripts') or {}
241                         for script_name, entry_point in iteritems(scripts):
242                             if entry_point.module_name == module:
243                                 ver = dist.version
244                                 break
245                 if ver is None:
246                     raise RuntimeError('Could not determine version')
247             echo(message % {
248                 'prog': prog,
249                 'version': ver,
250             })
251             ctx.exit()
252 
253         attrs.setdefault('is_flag', True)
254         attrs.setdefault('expose_value', False)
255         attrs.setdefault('is_eager', True)
256         attrs.setdefault('help', 'Show the version and exit.')
257         attrs['callback'] = callback
258         return option(*(param_decls or ('--version',)), **attrs)(f)
259     return decorator
260 
261 
262 def help_option(*param_decls, **attrs):
263     """Adds a ``--help`` option which immediately ends the program
264     printing out the help page.  This is usually unnecessary to add as
265     this is added by default to all commands unless suppressed.
266 
267     Like :func:`version_option`, this is implemented as eager option that
268     prints in the callback and exits.
269 
270     All arguments are forwarded to :func:`option`.
271     """
272     def decorator(f):
273         def callback(ctx, param, value):
274             if value and not ctx.resilient_parsing:
275                 echo(ctx.get_help())
276                 ctx.exit()
277         attrs.setdefault('is_flag', True)
278         attrs.setdefault('expose_value', False)
279         attrs.setdefault('help', 'Show this message and exit.')
280         attrs.setdefault('is_eager', True)
281         attrs['callback'] = callback
282         return option(*(param_decls or ('--help',)), **attrs)(f)
283     return decorator
284 
285 
286 # Circular dependencies between core and decorators
287 from .core import Command, Group, Argument, Option
288
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/click/decorators.py b/click/decorators.py
--- a/click/decorators.py
+++ b/click/decorators.py
@@ -150,6 +150,8 @@
     :attr:`Command.params` list.
     """
     def decorator(f):
+        if 'help' in attrs:
+            attrs['help'] = inspect.cleandoc(attrs['help'])
         _param_memo(f, Option(param_decls, **attrs))
         return f
     return decorator

{"golden_diff": "diff --git a/click/decorators.py b/click/decorators.py\n--- a/click/decorators.py\n+++ b/click/decorators.py\n@@ -150,6 +150,8 @@\n     :attr:`Command.params` list.\n     \"\"\"\n     def decorator(f):\n+        if 'help' in attrs:\n+            attrs['help'] = inspect.cleandoc(attrs['help'])\n         _param_memo(f, Option(param_decls, **attrs))\n         return f\n     return decorator\n", "issue": "Automatically dedent help text of options?\n```\nimport click\n\n@click.command()\n@click.option('--foo', help=\"\"\"\n    heyho\n\n    i am\n\n    multiline\n\"\"\")\ndef cli(foo):\n    click.echo(foo)\n\ncli()\n```\n\nThis currently does not remove the leading whitespace from each paragraph in the help text for `--foo`:\n\n```\nuntitaker@untibox:~/projects/click, branch master\n$ python lol.py --help\nUsage: lol.py [OPTIONS]\n\nOptions:\n  --foo TEXT\n                  heyho\n\n                  i am\n\n                  multiline\n  --help      Show this message and exit.\n```\n\nAlthough i am not sure if help texts for options are even supposed to get that\ncomplex.\n\n", "before_files": [{"content": "import sys\nimport inspect\n\nfrom functools import update_wrapper\n\nfrom ._compat import iteritems\nfrom .utils import echo\n\n\ndef pass_context(f):\n    \"\"\"Marks a callback as wanting to receive the current context\n    object as first argument.\n    \"\"\"\n    f.__click_pass_context__ = True\n    return f\n\n\ndef pass_obj(f):\n    \"\"\"Similar to :func:`pass_context`, but only pass the object on the\n    context onwards (:attr:`Context.obj`).  This is useful if that object\n    represents the state of a nested system.\n    \"\"\"\n    @pass_context\n    def new_func(*args, **kwargs):\n        ctx = args[0]\n        return ctx.invoke(f, ctx.obj, *args[1:], **kwargs)\n    return update_wrapper(new_func, f)\n\n\ndef make_pass_decorator(object_type, ensure=False):\n    \"\"\"Given an object type this creates a decorator that will work\n    similar to :func:`pass_obj` but instead of passing the object of the\n    current context, it will find the innermost context of type\n    :func:`object_type`.\n\n    This generates a decorator that works roughly like this::\n\n        from functools import update_wrapper\n\n        def decorator(f):\n            @pass_context\n            def new_func(ctx, *args, **kwargs):\n                obj = ctx.find_object(object_type)\n                return ctx.invoke(f, obj, *args, **kwargs)\n            return update_wrapper(new_func, f)\n        return decorator\n\n    :param object_type: the type of the object to pass.\n    :param ensure: if set to `True`, a new object will be created and\n                   remembered on the context if it's not there yet.\n    \"\"\"\n    def decorator(f):\n        @pass_context\n        def new_func(*args, **kwargs):\n            ctx = args[0]\n            if ensure:\n                obj = ctx.ensure_object(object_type)\n            else:\n                obj = ctx.find_object(object_type)\n            if obj is None:\n                raise RuntimeError('Managed to invoke callback without a '\n                                   'context object of type %r existing'\n                                   % object_type.__name__)\n            return ctx.invoke(f, obj, *args[1:], **kwargs)\n        return update_wrapper(new_func, f)\n    return decorator\n\n\ndef _make_command(f, name, attrs, cls):\n    if isinstance(f, Command):\n        raise TypeError('Attempted to convert a callback into a '\n                        'command twice.')\n    try:\n        params = f.__click_params__\n        params.reverse()\n        del f.__click_params__\n    except AttributeError:\n        params = []\n    help = inspect.getdoc(f)\n    if isinstance(help, bytes):\n        help = help.decode('utf-8')\n    attrs.setdefault('help', help)\n    return cls(name=name or f.__name__.lower(),\n               callback=f, params=params, **attrs)\n\n\ndef command(name=None, cls=None, **attrs):\n    \"\"\"Creates a new :class:`Command` and uses the decorated function as\n    callback.  This will also automatically attach all decorated\n    :func:`option`\\s and :func:`argument`\\s as parameters to the command.\n\n    The name of the command defaults to the name of the function.  If you\n    want to change that, you can pass the intended name as the first\n    argument.\n\n    All keyword arguments are forwarded to the underlying command class.\n\n    Once decorated the function turns into a :class:`Command` instance\n    that can be invoked as a command line utility or be attached to a\n    command :class:`Group`.\n\n    :param name: the name of the command.  This defaults to the function\n                 name.\n    :param cls: the command class to instantiate.  This defaults to\n                :class:`Command`.\n    \"\"\"\n    if cls is None:\n        cls = Command\n    def decorator(f):\n        return _make_command(f, name, attrs, cls)\n    return decorator\n\n\ndef group(name=None, **attrs):\n    \"\"\"Creates a new :class:`Group` with a function as callback.  This\n    works otherwise the same as :func:`command` just that the `cls`\n    parameter is set to :class:`Group`.\n    \"\"\"\n    attrs.setdefault('cls', Group)\n    return command(name, **attrs)\n\n\ndef _param_memo(f, param):\n    if isinstance(f, Command):\n        f.params.append(param)\n    else:\n        if not hasattr(f, '__click_params__'):\n            f.__click_params__ = []\n        f.__click_params__.append(param)\n\n\ndef argument(*param_decls, **attrs):\n    \"\"\"Attaches an option to the command.  All positional arguments are\n    passed as parameter declarations to :class:`Argument`; all keyword\n    arguments are forwarded unchanged.  This is equivalent to creating an\n    :class:`Option` instance manually and attaching it to the\n    :attr:`Command.params` list.\n    \"\"\"\n    def decorator(f):\n        _param_memo(f, Argument(param_decls, **attrs))\n        return f\n    return decorator\n\n\ndef option(*param_decls, **attrs):\n    \"\"\"Attaches an option to the command.  All positional arguments are\n    passed as parameter declarations to :class:`Option`; all keyword\n    arguments are forwarded unchanged.  This is equivalent to creating an\n    :class:`Option` instance manually and attaching it to the\n    :attr:`Command.params` list.\n    \"\"\"\n    def decorator(f):\n        _param_memo(f, Option(param_decls, **attrs))\n        return f\n    return decorator\n\n\ndef confirmation_option(*param_decls, **attrs):\n    \"\"\"Shortcut for confirmation prompts that can be ignored by passing\n    ``--yes`` as parameter.\n\n    This is equivalent to decorating a function with :func:`option` with\n    the following parameters::\n\n        def callback(ctx, param, value):\n            if not value:\n                ctx.abort()\n\n        @click.command()\n        @click.option('--yes', is_flag=True, callback=callback,\n                      expose_value=False, prompt='Do you want to continue?')\n        def dropdb():\n            pass\n    \"\"\"\n    def decorator(f):\n        def callback(ctx, param, value):\n            if not value:\n                ctx.abort()\n        attrs.setdefault('is_flag', True)\n        attrs.setdefault('callback', callback)\n        attrs.setdefault('expose_value', False)\n        attrs.setdefault('prompt', 'Do you want to continue?')\n        attrs.setdefault('help', 'Confirm the action without prompting.')\n        return option(*(param_decls or ('--yes',)), **attrs)(f)\n    return decorator\n\n\ndef password_option(*param_decls, **attrs):\n    \"\"\"Shortcut for password prompts.\n\n    This is equivalent to decorating a function with :func:`option` with\n    the following parameters::\n\n        @click.command()\n        @click.option('--password', prompt=True, confirmation_prompt=True,\n                      hide_input=True)\n        def changeadmin(password):\n            pass\n    \"\"\"\n    def decorator(f):\n        attrs.setdefault('prompt', True)\n        attrs.setdefault('confirmation_prompt', True)\n        attrs.setdefault('hide_input', True)\n        return option(*(param_decls or ('--password',)), **attrs)(f)\n    return decorator\n\n\ndef version_option(version=None, *param_decls, **attrs):\n    \"\"\"Adds a ``--version`` option which immediately ends the program\n    printing out the version number.  This is implemented as an eager\n    option that prints the version and exits the program in the callback.\n\n    :param version: the version number to show.  If not provided click\n                    attempts an auto discovery via setuptools.\n    :param prog_name: the name of the program (defaults to autodetection)\n    :param message: custom message to show instead of the default\n                    (``'%(prog)s, version %(version)s'``)\n    :param others: everything else is forwarded to :func:`option`.\n    \"\"\"\n    if version is None:\n        module = sys._getframe(1).f_globals.get('__name__')\n    def decorator(f):\n        prog_name = attrs.pop('prog_name', None)\n        message = attrs.pop('message', '%(prog)s, version %(version)s')\n\n        def callback(ctx, param, value):\n            if not value or ctx.resilient_parsing:\n                return\n            prog = prog_name\n            if prog is None:\n                prog = ctx.find_root().info_name\n            ver = version\n            if ver is None:\n                try:\n                    import pkg_resources\n                except ImportError:\n                    pass\n                else:\n                    for dist in pkg_resources.working_set:\n                        scripts = dist.get_entry_map().get('console_scripts') or {}\n                        for script_name, entry_point in iteritems(scripts):\n                            if entry_point.module_name == module:\n                                ver = dist.version\n                                break\n                if ver is None:\n                    raise RuntimeError('Could not determine version')\n            echo(message % {\n                'prog': prog,\n                'version': ver,\n            })\n            ctx.exit()\n\n        attrs.setdefault('is_flag', True)\n        attrs.setdefault('expose_value', False)\n        attrs.setdefault('is_eager', True)\n        attrs.setdefault('help', 'Show the version and exit.')\n        attrs['callback'] = callback\n        return option(*(param_decls or ('--version',)), **attrs)(f)\n    return decorator\n\n\ndef help_option(*param_decls, **attrs):\n    \"\"\"Adds a ``--help`` option which immediately ends the program\n    printing out the help page.  This is usually unnecessary to add as\n    this is added by default to all commands unless suppressed.\n\n    Like :func:`version_option`, this is implemented as eager option that\n    prints in the callback and exits.\n\n    All arguments are forwarded to :func:`option`.\n    \"\"\"\n    def decorator(f):\n        def callback(ctx, param, value):\n            if value and not ctx.resilient_parsing:\n                echo(ctx.get_help())\n                ctx.exit()\n        attrs.setdefault('is_flag', True)\n        attrs.setdefault('expose_value', False)\n        attrs.setdefault('help', 'Show this message and exit.')\n        attrs.setdefault('is_eager', True)\n        attrs['callback'] = callback\n        return option(*(param_decls or ('--help',)), **attrs)(f)\n    return decorator\n\n\n# Circular dependencies between core and decorators\nfrom .core import Command, Group, Argument, Option\n", "path": "click/decorators.py"}], "after_files": [{"content": "import sys\nimport inspect\n\nfrom functools import update_wrapper\n\nfrom ._compat import iteritems\nfrom .utils import echo\n\n\ndef pass_context(f):\n    \"\"\"Marks a callback as wanting to receive the current context\n    object as first argument.\n    \"\"\"\n    f.__click_pass_context__ = True\n    return f\n\n\ndef pass_obj(f):\n    \"\"\"Similar to :func:`pass_context`, but only pass the object on the\n    context onwards (:attr:`Context.obj`).  This is useful if that object\n    represents the state of a nested system.\n    \"\"\"\n    @pass_context\n    def new_func(*args, **kwargs):\n        ctx = args[0]\n        return ctx.invoke(f, ctx.obj, *args[1:], **kwargs)\n    return update_wrapper(new_func, f)\n\n\ndef make_pass_decorator(object_type, ensure=False):\n    \"\"\"Given an object type this creates a decorator that will work\n    similar to :func:`pass_obj` but instead of passing the object of the\n    current context, it will find the innermost context of type\n    :func:`object_type`.\n\n    This generates a decorator that works roughly like this::\n\n        from functools import update_wrapper\n\n        def decorator(f):\n            @pass_context\n            def new_func(ctx, *args, **kwargs):\n                obj = ctx.find_object(object_type)\n                return ctx.invoke(f, obj, *args, **kwargs)\n            return update_wrapper(new_func, f)\n        return decorator\n\n    :param object_type: the type of the object to pass.\n    :param ensure: if set to `True`, a new object will be created and\n                   remembered on the context if it's not there yet.\n    \"\"\"\n    def decorator(f):\n        @pass_context\n        def new_func(*args, **kwargs):\n            ctx = args[0]\n            if ensure:\n                obj = ctx.ensure_object(object_type)\n            else:\n                obj = ctx.find_object(object_type)\n            if obj is None:\n                raise RuntimeError('Managed to invoke callback without a '\n                                   'context object of type %r existing'\n                                   % object_type.__name__)\n            return ctx.invoke(f, obj, *args[1:], **kwargs)\n        return update_wrapper(new_func, f)\n    return decorator\n\n\ndef _make_command(f, name, attrs, cls):\n    if isinstance(f, Command):\n        raise TypeError('Attempted to convert a callback into a '\n                        'command twice.')\n    try:\n        params = f.__click_params__\n        params.reverse()\n        del f.__click_params__\n    except AttributeError:\n        params = []\n    help = inspect.getdoc(f)\n    if isinstance(help, bytes):\n        help = help.decode('utf-8')\n    attrs.setdefault('help', help)\n    return cls(name=name or f.__name__.lower(),\n               callback=f, params=params, **attrs)\n\n\ndef command(name=None, cls=None, **attrs):\n    \"\"\"Creates a new :class:`Command` and uses the decorated function as\n    callback.  This will also automatically attach all decorated\n    :func:`option`\\s and :func:`argument`\\s as parameters to the command.\n\n    The name of the command defaults to the name of the function.  If you\n    want to change that, you can pass the intended name as the first\n    argument.\n\n    All keyword arguments are forwarded to the underlying command class.\n\n    Once decorated the function turns into a :class:`Command` instance\n    that can be invoked as a command line utility or be attached to a\n    command :class:`Group`.\n\n    :param name: the name of the command.  This defaults to the function\n                 name.\n    :param cls: the command class to instantiate.  This defaults to\n                :class:`Command`.\n    \"\"\"\n    if cls is None:\n        cls = Command\n    def decorator(f):\n        return _make_command(f, name, attrs, cls)\n    return decorator\n\n\ndef group(name=None, **attrs):\n    \"\"\"Creates a new :class:`Group` with a function as callback.  This\n    works otherwise the same as :func:`command` just that the `cls`\n    parameter is set to :class:`Group`.\n    \"\"\"\n    attrs.setdefault('cls', Group)\n    return command(name, **attrs)\n\n\ndef _param_memo(f, param):\n    if isinstance(f, Command):\n        f.params.append(param)\n    else:\n        if not hasattr(f, '__click_params__'):\n            f.__click_params__ = []\n        f.__click_params__.append(param)\n\n\ndef argument(*param_decls, **attrs):\n    \"\"\"Attaches an option to the command.  All positional arguments are\n    passed as parameter declarations to :class:`Argument`; all keyword\n    arguments are forwarded unchanged.  This is equivalent to creating an\n    :class:`Option` instance manually and attaching it to the\n    :attr:`Command.params` list.\n    \"\"\"\n    def decorator(f):\n        _param_memo(f, Argument(param_decls, **attrs))\n        return f\n    return decorator\n\n\ndef option(*param_decls, **attrs):\n    \"\"\"Attaches an option to the command.  All positional arguments are\n    passed as parameter declarations to :class:`Option`; all keyword\n    arguments are forwarded unchanged.  This is equivalent to creating an\n    :class:`Option` instance manually and attaching it to the\n    :attr:`Command.params` list.\n    \"\"\"\n    def decorator(f):\n        if 'help' in attrs:\n            attrs['help'] = inspect.cleandoc(attrs['help'])\n        _param_memo(f, Option(param_decls, **attrs))\n        return f\n    return decorator\n\n\ndef confirmation_option(*param_decls, **attrs):\n    \"\"\"Shortcut for confirmation prompts that can be ignored by passing\n    ``--yes`` as parameter.\n\n    This is equivalent to decorating a function with :func:`option` with\n    the following parameters::\n\n        def callback(ctx, param, value):\n            if not value:\n                ctx.abort()\n\n        @click.command()\n        @click.option('--yes', is_flag=True, callback=callback,\n                      expose_value=False, prompt='Do you want to continue?')\n        def dropdb():\n            pass\n    \"\"\"\n    def decorator(f):\n        def callback(ctx, param, value):\n            if not value:\n                ctx.abort()\n        attrs.setdefault('is_flag', True)\n        attrs.setdefault('callback', callback)\n        attrs.setdefault('expose_value', False)\n        attrs.setdefault('prompt', 'Do you want to continue?')\n        attrs.setdefault('help', 'Confirm the action without prompting.')\n        return option(*(param_decls or ('--yes',)), **attrs)(f)\n    return decorator\n\n\ndef password_option(*param_decls, **attrs):\n    \"\"\"Shortcut for password prompts.\n\n    This is equivalent to decorating a function with :func:`option` with\n    the following parameters::\n\n        @click.command()\n        @click.option('--password', prompt=True, confirmation_prompt=True,\n                      hide_input=True)\n        def changeadmin(password):\n            pass\n    \"\"\"\n    def decorator(f):\n        attrs.setdefault('prompt', True)\n        attrs.setdefault('confirmation_prompt', True)\n        attrs.setdefault('hide_input', True)\n        return option(*(param_decls or ('--password',)), **attrs)(f)\n    return decorator\n\n\ndef version_option(version=None, *param_decls, **attrs):\n    \"\"\"Adds a ``--version`` option which immediately ends the program\n    printing out the version number.  This is implemented as an eager\n    option that prints the version and exits the program in the callback.\n\n    :param version: the version number to show.  If not provided click\n                    attempts an auto discovery via setuptools.\n    :param prog_name: the name of the program (defaults to autodetection)\n    :param message: custom message to show instead of the default\n                    (``'%(prog)s, version %(version)s'``)\n    :param others: everything else is forwarded to :func:`option`.\n    \"\"\"\n    if version is None:\n        module = sys._getframe(1).f_globals.get('__name__')\n    def decorator(f):\n        prog_name = attrs.pop('prog_name', None)\n        message = attrs.pop('message', '%(prog)s, version %(version)s')\n\n        def callback(ctx, param, value):\n            if not value or ctx.resilient_parsing:\n                return\n            prog = prog_name\n            if prog is None:\n                prog = ctx.find_root().info_name\n            ver = version\n            if ver is None:\n                try:\n                    import pkg_resources\n                except ImportError:\n                    pass\n                else:\n                    for dist in pkg_resources.working_set:\n                        scripts = dist.get_entry_map().get('console_scripts') or {}\n                        for script_name, entry_point in iteritems(scripts):\n                            if entry_point.module_name == module:\n                                ver = dist.version\n                                break\n                if ver is None:\n                    raise RuntimeError('Could not determine version')\n            echo(message % {\n                'prog': prog,\n                'version': ver,\n            })\n            ctx.exit()\n\n        attrs.setdefault('is_flag', True)\n        attrs.setdefault('expose_value', False)\n        attrs.setdefault('is_eager', True)\n        attrs.setdefault('help', 'Show the version and exit.')\n        attrs['callback'] = callback\n        return option(*(param_decls or ('--version',)), **attrs)(f)\n    return decorator\n\n\ndef help_option(*param_decls, **attrs):\n    \"\"\"Adds a ``--help`` option which immediately ends the program\n    printing out the help page.  This is usually unnecessary to add as\n    this is added by default to all commands unless suppressed.\n\n    Like :func:`version_option`, this is implemented as eager option that\n    prints in the callback and exits.\n\n    All arguments are forwarded to :func:`option`.\n    \"\"\"\n    def decorator(f):\n        def callback(ctx, param, value):\n            if value and not ctx.resilient_parsing:\n                echo(ctx.get_help())\n                ctx.exit()\n        attrs.setdefault('is_flag', True)\n        attrs.setdefault('expose_value', False)\n        attrs.setdefault('help', 'Show this message and exit.')\n        attrs.setdefault('is_eager', True)\n        attrs['callback'] = callback\n        return option(*(param_decls or ('--help',)), **attrs)(f)\n    return decorator\n\n\n# Circular dependencies between core and decorators\nfrom .core import Command, Group, Argument, Option\n", "path": "click/decorators.py"}]}