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
Provenance
- Commit
e413626- Tree
3e337a4- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
c10e6a1
1 file changed+49 added−0 removed
modified:docs/commands.rst+49 added
272 unmodified lines273 274 In case a command exists in more than one source, the first source wins.275 276 277+.. _multi-command-chaining:278+279 Multi Command Chaining280 ----------------------281 282 .. versionadded:: 3.0220 unmodified lines503 504 .. click:run::505 506 invoke(cli, prog_name='cli', args=['runserver'])507+508+509+Command Return Values510+---------------------511+512+.. versionadded:: 3.0513+514+One of the new introductions in Click 3.0 is the full support for return515+values from command callbacks. This enables a whole range of features516+that were previously hard to implement.517+518+In essence any command callback can now return a value. This return value519+is bubbled to certain receivers. One usecase for this has already been520+show in the example of :ref:`multi-command-chaining` where it has been521+demonstrated that chained multi commands can have callbacks that process522+all return values.523+524+When working with command return values in Click, this is what you need to525+know:526+527+- 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:530+531+ * 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.541+542+- 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.545+546+- 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).550+551+- 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.