We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
make_pass_decorator strips argument
The inner most wrapper of make_pass_decorator invokes a function with `*args[1:]` which strips an argument.

A smaller example could be made but the following is the [invoking other commands](http://click.pocoo.org/6/advanced/#invoking-other-commands) example from the docs modified to also take in a custom config object.

The only difference between `dist_working` and `dist_broken` is the order of the decorators and consequently the parameters they take.

In my opinion they should both be valid and work.  What happens in `dist_broken` is, like the title says, the `make_pass_decorator` wrapper invokes the function with `*args[1:]` which removes the context object put there by the previous decorator.

```python
import click


class MyConfig(object):
    def __init__(self, verbose):
        self.verbose = verbose


pass_config = click.make_pass_decorator(MyConfig)


@click.group()
@click.option('--verbose', '-v', is_flag=True)
@click.pass_context
def cli(ctx, verbose):
    ctx.obj = MyConfig(verbose=verbose)


@cli.command()
@click.option('--count', default=1)
def test(count):
    click.echo('Count: %d' % count)


@cli.command('dist-working')
@click.option('--count', default=1)
@pass_config
@click.pass_context
def dist_working(ctx, cfg, count):
    if cfg.verbose:
        click.echo('about to forward')
    ctx.forward(test)
    if cfg.verbose:
        click.echo('about to invoke')
    ctx.invoke(test, count=42)


@cli.command('dist-broken')
@click.option('--count', default=1)
@click.pass_context
@pass_config
def dist_broken(cfg, ctx, count):
    if cfg.verbose:
        click.echo('about to forward')
    ctx.forward(test)
    if cfg.verbose:
        click.echo('about to invoke')
    ctx.invoke(test, count=42)
```


--- 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 ._unicodefun import _check_for_unicode_literals
8 from .utils import echo
9 from .globals import get_current_context
10 
11 
12 def pass_context(f):
13     """Marks a callback as wanting to receive the current context
14     object as first argument.
15     """
16     def new_func(*args, **kwargs):
17         return f(get_current_context(), *args, **kwargs)
18     return update_wrapper(new_func, f)
19 
20 
21 def pass_obj(f):
22     """Similar to :func:`pass_context`, but only pass the object on the
23     context onwards (:attr:`Context.obj`).  This is useful if that object
24     represents the state of a nested system.
25     """
26     def new_func(*args, **kwargs):
27         return f(get_current_context().obj, *args, **kwargs)
28     return update_wrapper(new_func, f)
29 
30 
31 def make_pass_decorator(object_type, ensure=False):
32     """Given an object type this creates a decorator that will work
33     similar to :func:`pass_obj` but instead of passing the object of the
34     current context, it will find the innermost context of type
35     :func:`object_type`.
36 
37     This generates a decorator that works roughly like this::
38 
39         from functools import update_wrapper
40 
41         def decorator(f):
42             @pass_context
43             def new_func(ctx, *args, **kwargs):
44                 obj = ctx.find_object(object_type)
45                 return ctx.invoke(f, obj, *args, **kwargs)
46             return update_wrapper(new_func, f)
47         return decorator
48 
49     :param object_type: the type of the object to pass.
50     :param ensure: if set to `True`, a new object will be created and
51                    remembered on the context if it's not there yet.
52     """
53     def decorator(f):
54         def new_func(*args, **kwargs):
55             ctx = get_current_context()
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 = attrs.get('help')
80     if help is None:
81         help = inspect.getdoc(f)
82         if isinstance(help, bytes):
83             help = help.decode('utf-8')
84     else:
85         help = inspect.cleandoc(help)
86     attrs['help'] = help
87     _check_for_unicode_literals()
88     return cls(name=name or f.__name__.lower().replace('_', '-'),
89                callback=f, params=params, **attrs)
90 
91 
92 def command(name=None, cls=None, **attrs):
93     r"""Creates a new :class:`Command` and uses the decorated function as
94     callback.  This will also automatically attach all decorated
95     :func:`option`\s and :func:`argument`\s as parameters to the command.
96 
97     The name of the command defaults to the name of the function.  If you
98     want to change that, you can pass the intended name as the first
99     argument.
100 
101     All keyword arguments are forwarded to the underlying command class.
102 
103     Once decorated the function turns into a :class:`Command` instance
104     that can be invoked as a command line utility or be attached to a
105     command :class:`Group`.
106 
107     :param name: the name of the command.  This defaults to the function
108                  name with underscores replaced by dashes.
109     :param cls: the command class to instantiate.  This defaults to
110                 :class:`Command`.
111     """
112     if cls is None:
113         cls = Command
114     def decorator(f):
115         cmd = _make_command(f, name, attrs, cls)
116         cmd.__doc__ = f.__doc__
117         return cmd
118     return decorator
119 
120 
121 def group(name=None, **attrs):
122     """Creates a new :class:`Group` with a function as callback.  This
123     works otherwise the same as :func:`command` just that the `cls`
124     parameter is set to :class:`Group`.
125     """
126     attrs.setdefault('cls', Group)
127     return command(name, **attrs)
128 
129 
130 def _param_memo(f, param):
131     if isinstance(f, Command):
132         f.params.append(param)
133     else:
134         if not hasattr(f, '__click_params__'):
135             f.__click_params__ = []
136         f.__click_params__.append(param)
137 
138 
139 def argument(*param_decls, **attrs):
140     """Attaches an argument to the command.  All positional arguments are
141     passed as parameter declarations to :class:`Argument`; all keyword
142     arguments are forwarded unchanged (except ``cls``).
143     This is equivalent to creating an :class:`Argument` instance manually
144     and attaching it to the :attr:`Command.params` list.
145 
146     :param cls: the argument class to instantiate.  This defaults to
147                 :class:`Argument`.
148     """
149     def decorator(f):
150         ArgumentClass = attrs.pop('cls', Argument)
151         _param_memo(f, ArgumentClass(param_decls, **attrs))
152         return f
153     return decorator
154 
155 
156 def option(*param_decls, **attrs):
157     """Attaches an option to the command.  All positional arguments are
158     passed as parameter declarations to :class:`Option`; all keyword
159     arguments are forwarded unchanged (except ``cls``).
160     This is equivalent to creating an :class:`Option` instance manually
161     and attaching it to the :attr:`Command.params` list.
162 
163     :param cls: the option class to instantiate.  This defaults to
164                 :class:`Option`.
165     """
166     def decorator(f):
167         # Issue 926, copy attrs, so pre-defined options can re-use the same cls=
168         option_attrs = attrs.copy()
169 
170         if 'help' in option_attrs:
171             option_attrs['help'] = inspect.cleandoc(option_attrs['help'])
172         OptionClass = option_attrs.pop('cls', Option)
173         _param_memo(f, OptionClass(param_decls, **option_attrs))
174         return f
175     return decorator
176 
177 
178 def confirmation_option(*param_decls, **attrs):
179     """Shortcut for confirmation prompts that can be ignored by passing
180     ``--yes`` as parameter.
181 
182     This is equivalent to decorating a function with :func:`option` with
183     the following parameters::
184 
185         def callback(ctx, param, value):
186             if not value:
187                 ctx.abort()
188 
189         @click.command()
190         @click.option('--yes', is_flag=True, callback=callback,
191                       expose_value=False, prompt='Do you want to continue?')
192         def dropdb():
193             pass
194     """
195     def decorator(f):
196         def callback(ctx, param, value):
197             if not value:
198                 ctx.abort()
199         attrs.setdefault('is_flag', True)
200         attrs.setdefault('callback', callback)
201         attrs.setdefault('expose_value', False)
202         attrs.setdefault('prompt', 'Do you want to continue?')
203         attrs.setdefault('help', 'Confirm the action without prompting.')
204         return option(*(param_decls or ('--yes',)), **attrs)(f)
205     return decorator
206 
207 
208 def password_option(*param_decls, **attrs):
209     """Shortcut for password prompts.
210 
211     This is equivalent to decorating a function with :func:`option` with
212     the following parameters::
213 
214         @click.command()
215         @click.option('--password', prompt=True, confirmation_prompt=True,
216                       hide_input=True)
217         def changeadmin(password):
218             pass
219     """
220     def decorator(f):
221         attrs.setdefault('prompt', True)
222         attrs.setdefault('confirmation_prompt', True)
223         attrs.setdefault('hide_input', True)
224         return option(*(param_decls or ('--password',)), **attrs)(f)
225     return decorator
226 
227 
228 def version_option(version=None, *param_decls, **attrs):
229     """Adds a ``--version`` option which immediately ends the program
230     printing out the version number.  This is implemented as an eager
231     option that prints the version and exits the program in the callback.
232 
233     :param version: the version number to show.  If not provided Click
234                     attempts an auto discovery via setuptools.
235     :param prog_name: the name of the program (defaults to autodetection)
236     :param message: custom message to show instead of the default
237                     (``'%(prog)s, version %(version)s'``)
238     :param others: everything else is forwarded to :func:`option`.
239     """
240     if version is None:
241         if hasattr(sys, '_getframe'):
242             module = sys._getframe(1).f_globals.get('__name__')
243         else:
244             module = ''
245 
246     def decorator(f):
247         prog_name = attrs.pop('prog_name', None)
248         message = attrs.pop('message', '%(prog)s, version %(version)s')
249 
250         def callback(ctx, param, value):
251             if not value or ctx.resilient_parsing:
252                 return
253             prog = prog_name
254             if prog is None:
255                 prog = ctx.find_root().info_name
256             ver = version
257             if ver is None:
258                 try:
259                     import pkg_resources
260                 except ImportError:
261                     pass
262                 else:
263                     for dist in pkg_resources.working_set:
264                         scripts = dist.get_entry_map().get('console_scripts') or {}
265                         for script_name, entry_point in iteritems(scripts):
266                             if entry_point.module_name == module:
267                                 ver = dist.version
268                                 break
269                 if ver is None:
270                     raise RuntimeError('Could not determine version')
271             echo(message % {
272                 'prog': prog,
273                 'version': ver,
274             }, color=ctx.color)
275             ctx.exit()
276 
277         attrs.setdefault('is_flag', True)
278         attrs.setdefault('expose_value', False)
279         attrs.setdefault('is_eager', True)
280         attrs.setdefault('help', 'Show the version and exit.')
281         attrs['callback'] = callback
282         return option(*(param_decls or ('--version',)), **attrs)(f)
283     return decorator
284 
285 
286 def help_option(*param_decls, **attrs):
287     """Adds a ``--help`` option which immediately ends the program
288     printing out the help page.  This is usually unnecessary to add as
289     this is added by default to all commands unless suppressed.
290 
291     Like :func:`version_option`, this is implemented as eager option that
292     prints in the callback and exits.
293 
294     All arguments are forwarded to :func:`option`.
295     """
296     def decorator(f):
297         def callback(ctx, param, value):
298             if value and not ctx.resilient_parsing:
299                 echo(ctx.get_help(), color=ctx.color)
300                 ctx.exit()
301         attrs.setdefault('is_flag', True)
302         attrs.setdefault('expose_value', False)
303         attrs.setdefault('help', 'Show this message and exit.')
304         attrs.setdefault('is_eager', True)
305         attrs['callback'] = callback
306         return option(*(param_decls or ('--help',)), **attrs)(f)
307     return decorator
308 
309 
310 # Circular dependencies between core and decorators
311 from .core import Command, Group, Argument, Option
312
```
--- 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
@@ -61,7 +61,7 @@
                 raise RuntimeError('Managed to invoke callback without a '
                                    'context object of type %r existing'
                                    % object_type.__name__)
-            return ctx.invoke(f, obj, *args[1:], **kwargs)
+            return ctx.invoke(f, obj, *args, **kwargs)
         return update_wrapper(new_func, 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@@ -61,7 +61,7 @@\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 ctx.invoke(f, obj, *args, **kwargs)\n         return update_wrapper(new_func, f)\n     return decorator\n", "issue": "make_pass_decorator strips argument\nThe inner most wrapper of make_pass_decorator invokes a function with `*args[1:]` which strips an argument.\r\n\r\nA smaller example could be made but the following is the [invoking other commands](http://click.pocoo.org/6/advanced/#invoking-other-commands) example from the docs modified to also take in a custom config object.\r\n\r\nThe only difference between `dist_working` and `dist_broken` is the order of the decorators and consequently the parameters they take.\r\n\r\nIn my opinion they should both be valid and work.  What happens in `dist_broken` is, like the title says, the `make_pass_decorator` wrapper invokes the function with `*args[1:]` which removes the context object put there by the previous decorator.\r\n\r\n```python\r\nimport click\r\n\r\n\r\nclass MyConfig(object):\r\n    def __init__(self, verbose):\r\n        self.verbose = verbose\r\n\r\n\r\npass_config = click.make_pass_decorator(MyConfig)\r\n\r\n\r\n@click.group()\r\n@click.option('--verbose', '-v', is_flag=True)\r\n@click.pass_context\r\ndef cli(ctx, verbose):\r\n    ctx.obj = MyConfig(verbose=verbose)\r\n\r\n\r\n@cli.command()\r\n@click.option('--count', default=1)\r\ndef test(count):\r\n    click.echo('Count: %d' % count)\r\n\r\n\r\n@cli.command('dist-working')\r\n@click.option('--count', default=1)\r\n@pass_config\r\n@click.pass_context\r\ndef dist_working(ctx, cfg, count):\r\n    if cfg.verbose:\r\n        click.echo('about to forward')\r\n    ctx.forward(test)\r\n    if cfg.verbose:\r\n        click.echo('about to invoke')\r\n    ctx.invoke(test, count=42)\r\n\r\n\r\n@cli.command('dist-broken')\r\n@click.option('--count', default=1)\r\n@click.pass_context\r\n@pass_config\r\ndef dist_broken(cfg, ctx, count):\r\n    if cfg.verbose:\r\n        click.echo('about to forward')\r\n    ctx.forward(test)\r\n    if cfg.verbose:\r\n        click.echo('about to invoke')\r\n    ctx.invoke(test, count=42)\r\n```\r\n\n", "before_files": [{"content": "import sys\nimport inspect\n\nfrom functools import update_wrapper\n\nfrom ._compat import iteritems\nfrom ._unicodefun import _check_for_unicode_literals\nfrom .utils import echo\nfrom .globals import get_current_context\n\n\ndef pass_context(f):\n    \"\"\"Marks a callback as wanting to receive the current context\n    object as first argument.\n    \"\"\"\n    def new_func(*args, **kwargs):\n        return f(get_current_context(), *args, **kwargs)\n    return update_wrapper(new_func, 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    def new_func(*args, **kwargs):\n        return f(get_current_context().obj, *args, **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        def new_func(*args, **kwargs):\n            ctx = get_current_context()\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 = attrs.get('help')\n    if help is None:\n        help = inspect.getdoc(f)\n        if isinstance(help, bytes):\n            help = help.decode('utf-8')\n    else:\n        help = inspect.cleandoc(help)\n    attrs['help'] = help\n    _check_for_unicode_literals()\n    return cls(name=name or f.__name__.lower().replace('_', '-'),\n               callback=f, params=params, **attrs)\n\n\ndef command(name=None, cls=None, **attrs):\n    r\"\"\"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 with underscores replaced by dashes.\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        cmd = _make_command(f, name, attrs, cls)\n        cmd.__doc__ = f.__doc__\n        return cmd\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 argument to the command.  All positional arguments are\n    passed as parameter declarations to :class:`Argument`; all keyword\n    arguments are forwarded unchanged (except ``cls``).\n    This is equivalent to creating an :class:`Argument` instance manually\n    and attaching it to the :attr:`Command.params` list.\n\n    :param cls: the argument class to instantiate.  This defaults to\n                :class:`Argument`.\n    \"\"\"\n    def decorator(f):\n        ArgumentClass = attrs.pop('cls', Argument)\n        _param_memo(f, ArgumentClass(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 (except ``cls``).\n    This is equivalent to creating an :class:`Option` instance manually\n    and attaching it to the :attr:`Command.params` list.\n\n    :param cls: the option class to instantiate.  This defaults to\n                :class:`Option`.\n    \"\"\"\n    def decorator(f):\n        # Issue 926, copy attrs, so pre-defined options can re-use the same cls=\n        option_attrs = attrs.copy()\n\n        if 'help' in option_attrs:\n            option_attrs['help'] = inspect.cleandoc(option_attrs['help'])\n        OptionClass = option_attrs.pop('cls', Option)\n        _param_memo(f, OptionClass(param_decls, **option_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        if hasattr(sys, '_getframe'):\n            module = sys._getframe(1).f_globals.get('__name__')\n        else:\n            module = ''\n\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            }, color=ctx.color)\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(), color=ctx.color)\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 ._unicodefun import _check_for_unicode_literals\nfrom .utils import echo\nfrom .globals import get_current_context\n\n\ndef pass_context(f):\n    \"\"\"Marks a callback as wanting to receive the current context\n    object as first argument.\n    \"\"\"\n    def new_func(*args, **kwargs):\n        return f(get_current_context(), *args, **kwargs)\n    return update_wrapper(new_func, 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    def new_func(*args, **kwargs):\n        return f(get_current_context().obj, *args, **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        def new_func(*args, **kwargs):\n            ctx = get_current_context()\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, **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 = attrs.get('help')\n    if help is None:\n        help = inspect.getdoc(f)\n        if isinstance(help, bytes):\n            help = help.decode('utf-8')\n    else:\n        help = inspect.cleandoc(help)\n    attrs['help'] = help\n    _check_for_unicode_literals()\n    return cls(name=name or f.__name__.lower().replace('_', '-'),\n               callback=f, params=params, **attrs)\n\n\ndef command(name=None, cls=None, **attrs):\n    r\"\"\"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 with underscores replaced by dashes.\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        cmd = _make_command(f, name, attrs, cls)\n        cmd.__doc__ = f.__doc__\n        return cmd\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 argument to the command.  All positional arguments are\n    passed as parameter declarations to :class:`Argument`; all keyword\n    arguments are forwarded unchanged (except ``cls``).\n    This is equivalent to creating an :class:`Argument` instance manually\n    and attaching it to the :attr:`Command.params` list.\n\n    :param cls: the argument class to instantiate.  This defaults to\n                :class:`Argument`.\n    \"\"\"\n    def decorator(f):\n        ArgumentClass = attrs.pop('cls', Argument)\n        _param_memo(f, ArgumentClass(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 (except ``cls``).\n    This is equivalent to creating an :class:`Option` instance manually\n    and attaching it to the :attr:`Command.params` list.\n\n    :param cls: the option class to instantiate.  This defaults to\n                :class:`Option`.\n    \"\"\"\n    def decorator(f):\n        # Issue 926, copy attrs, so pre-defined options can re-use the same cls=\n        option_attrs = attrs.copy()\n\n        if 'help' in option_attrs:\n            option_attrs['help'] = inspect.cleandoc(option_attrs['help'])\n        OptionClass = option_attrs.pop('cls', Option)\n        _param_memo(f, OptionClass(param_decls, **option_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        if hasattr(sys, '_getframe'):\n            module = sys._getframe(1).f_globals.get('__name__')\n        else:\n            module = ''\n\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            }, color=ctx.color)\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(), color=ctx.color)\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"}]}