Skip to content
Myr

Added some docs on return values from commands

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent c10e6a1 · Browse files · 1 file+49 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+49 added−0 removed

  • other:+49 added−0 removed

1 file+49 added−0 removed

modified:docs/commands.rst+49 added
272 unmodified lines
273274In case a command exists in more than one source, the first source wins.275276277.. _multi-command-chaining:278279Multi Command Chaining280----------------------281282.. versionadded:: 3.0
220 unmodified lines
503504.. click:run::505506 invoke(cli, prog_name='cli', args=['runserver'])507508509Command Return Values510---------------------511512.. versionadded:: 3.0513514One of the new introductions in Click 3.0 is the full support for return515values from command callbacks. This enables a whole range of features516that were previously hard to implement.517518In essence any command callback can now return a value. This return value519is bubbled to certain receivers. One usecase for this has already been520show in the example of :ref:`multi-command-chaining` where it has been521demonstrated that chained multi commands can have callbacks that process522all return values.523524When working with command return values in Click, this is what you need to525know:526527- The return value of a command callback is generally returned from the528 :meth:`BaseCommand.invoke` method. The exception to this rule has to529 do with :class:`Group`\s:530531 * In a group the return value is generally the return value of the532 subcommand invoked. The only exception to this rule is that the533 return value is the return value of the group callback if it's534 invoked without arguments and `invoke_without_command` is enabled.535 * If a group is set up for chaining then the return value is a list536 of all subcommands' results.537 * Return values of groups can be processed through a538 :attr:`MultiCommand.result_callback`. This is invoked with the539 list of all return values in chain mode, or the single return540 value in case of non chained commands.541542- The return value is bubbled through from the :meth:`Context.invoke`543 and :meth:`Context.forward` methods. This is useful in situations544 where you internally want to call into another command.545546- Click does not have any hard requirements for the return values and547 does not use them itself. This allows return values to be used for548 custom decorators or workflows (like in the multi command chaining549 example).550551- When a Click script is invoked as command line application (through552 :meth:`BaseCommand.main`) the return value is ignored unless the553 `standalone_mode` is disabled in which case it's bubbled through.