'Invokes a command callback in exactly the way it expects.  There
are two ways to invoke this method:
1.  the first argument can be a callback and all other arguments and
keyword arguments are forwarded directly to the function.
2.  the first argument is a click command object.  In that case all
arguments are forwarded as well but proper click parameters
(options and click arguments) must be keyword arguments and Click
will fill in defaults.
Note that before Click 3.2 keyword arguments were not properly filled
in against the intention of this code and no context was created.  For
more information about this change and why it was done in a bugfix
release see :ref:`upgrade-to-3.2`.'

def invoke(*args, **kwargs):

    (self, callback) = args[:2]
    ctx = self
    if isinstance(callback, Command):
        other_cmd = callback
        callback = other_cmd.callback
        ctx = Context(other_cmd, info_name=other_cmd.name, parent=self)
        if (callback is None):
            raise TypeError('The    given    command    does    not    have    a    callback    that    can    be    invoked.')
        for param in other_cmd.params:
            if ((param.name not in kwargs) and param.expose_value):
                kwargs[param.name] = param.get_default(ctx)
    args = args[2:]
    with augment_usage_errors(self):
        with ctx:
            return callback(*args, **kwargs)
