Move Commands doc from reST to MyST (#3243)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Rowlando13 · committed by GitHub · parents 89af4ae, 0dee0ec · Browse files · 2 files·+437 added−428 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+437 added−428 removed
- other:+437 added−428 removed
Provenance
- Commit
e3c87be- Tree
4247d4d- Author
Rowlando13 <67291205+Rowlando13@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
89af4ae- Parent 2
0dee0ec
2 files changed+437 added−428 removed
added:docs/commands.md+437 added
1+# Advanced Groups and Context2+3+```{currentmodule} click4+```5+6+In addition to the capabilities covered in the previous section, Groups have more advanced capabilities that leverage the Context.7+8+```{contents}9+---10+depth: 111+local: true12+---13+```14+15+## Callback Invocation16+17+For a regular command, the callback is executed whenever the command runs.18+If the script is the only command, it will always fire (unless a parameter19+callback prevents it. This for instance happens if someone passes20+`--help` to the script).21+22+For groups, the situation looks different. In this case, the callback fires23+whenever a subcommand fires. What this means in practice is that an outer24+command runs when an inner command runs:25+26+```{eval-rst}27+.. click:example::28+29+ @click.group()30+ @click.option('--debug/--no-debug', default=False)31+ def cli(debug):32+ click.echo(f"Debug mode is {'on' if debug else 'off'}")33+34+ @cli.command() # @cli, not @click!35+ def sync():36+ click.echo('Syncing')37+38+Here is what this looks like:39+40+.. click:run::41+42+ invoke(cli, prog_name='tool.py')43+ println()44+ invoke(cli, prog_name='tool.py', args=['--debug', 'sync'])45+```46+47+## Nested Handling and Contexts48+49+As you can see from the earlier example, the basic command group accepts a50+debug argument which is passed to its callback, but not to the sync51+command itself. The sync command only accepts its own arguments.52+53+This allows tools to act completely independent of each other, but how54+does one command talk to a nested one? The answer to this is the55+{class}`Context`.56+57+Each time a command is invoked, a new context is created and linked with the58+parent context. Normally, you can't see these contexts, but they are59+there. Contexts are passed to parameter callbacks together with the60+value automatically. Commands can also ask for the context to be passed61+by marking themselves with the {func}`pass_context` decorator. In that62+case, the context is passed as first argument.63+64+The context can also carry a program specified object that can be65+used for the program's purposes. What this means is that you can build a66+script like this:67+68+```{eval-rst}69+.. click:example::70+71+ @click.group()72+ @click.option('--debug/--no-debug', default=False)73+ @click.pass_context74+ def cli(ctx, debug):75+ # ensure that ctx.obj exists and is a dict (in case `cli()` is called76+ # by means other than the `if` block below)77+ ctx.ensure_object(dict)78+79+ ctx.obj['DEBUG'] = debug80+81+ @cli.command()82+ @click.pass_context83+ def sync(ctx):84+ click.echo(f"Debug is {'on' if ctx.obj['DEBUG'] else 'off'}")85+86+ if __name__ == '__main__':87+ cli(obj={})88+```89+90+If the object is provided, each context will pass the object onwards to91+its children, but at any level a context's object can be overridden. To92+reach to a parent, `context.parent` can be used.93+94+In addition to that, instead of passing an object down, nothing stops the95+application from modifying global state. For instance, you could just flip96+a global `DEBUG` variable and be done with it.97+98+## Decorating Commands99+100+As you have seen in the earlier example, a decorator can change how a101+command is invoked. What actually happens behind the scenes is that102+callbacks are always invoked through the {meth}`Context.invoke` method103+which automatically invokes a command correctly (by either passing the104+context or not).105+106+This is very useful when you want to write custom decorators. For107+instance, a common pattern would be to configure an object representing108+state and then storing it on the context and then to use a custom109+decorator to find the most recent object of this sort and pass it as first110+argument.111+112+For instance, the {func}`pass_obj` decorator can be implemented like this:113+114+```{eval-rst}115+.. click:example::116+117+ from functools import update_wrapper118+119+ def pass_obj(f):120+ @click.pass_context121+ def new_func(ctx, *args, **kwargs):122+ return ctx.invoke(f, ctx.obj, *args, **kwargs)123+ return update_wrapper(new_func, f)124+```125+126+The {meth}`Context.invoke` command will automatically invoke the function127+in the correct way, so the function will either be called with`f(ctx,128+obj)` or `f(obj)` depending on whether or not it itself is decorated with129+{func}`pass_context`.130+131+This is a very powerful concept that can be used to build very complex132+nested applications; see {ref}`complex-guide` for more information.133+134+(command-chaining)=135+136+## Command Chaining137+138+It is useful to invoke more than one subcommand in one call. For example,139+`my-app validate build upload` would invoke `validate`, then `build`, then140+`upload`. To implement this, pass `chain=True` when creating a group.141+142+```{eval-rst}143+.. click:example::144+145+ @click.group(chain=True)146+ def cli():147+ pass148+149+ @cli.command('validate')150+ def validate():151+ click.echo('validate')152+153+ @cli.command('build')154+ def build():155+ click.echo('build')156+157+You can invoke it like this:158+159+.. click:run::160+161+ invoke(cli, prog_name='my-app', args=['validate', 'build'])162+```163+164+When using chaining, there are a few restrictions:165+166+- Only the last command may use `nargs=-1` on an argument, otherwise the167+ parser will not be able to find further commands.168+- It is not possible to nest groups below a chain group.169+- On the command line, options must be specified before arguments for each170+ command in the chain.171+- The {attr}`Context.invoked_subcommand` attribute will be `'*'` because the172+ parser doesn't know the full list of commands that will run yet.173+174+(command-pipelines)=175+176+## Command Pipelines177+178+When using chaining, a common pattern is to have each command process the179+result of the previous command.180+181+A straightforward way to do this is to use {func}`make_pass_decorator` to pass182+a context object to each command, and store and read the data on that object.183+184+```{eval-rst}185+.. click:example::186+187+ pass_ns = click.make_pass_decorator(dict, ensure=True)188+189+ @click.group(chain=True)190+ @click.argument("name")191+ @pass_ns192+ def cli(ns, name):193+ ns["name"] = name194+195+ @cli.command196+ @pass_ns197+ def lower(ns):198+ ns["name"] = ns["name"].lower()199+200+ @cli.command201+ @pass_ns202+ def show(ns):203+ click.echo(ns["name"])204+205+.. click:run::206+207+ invoke(cli, prog_name="process", args=["Click", "show", "lower", "show"])208+```209+210+Another way to do this is to collect data returned by each command, then process211+it at the end of the chain. Use the group's {meth}`~Group.result_callback`212+decorator to register a function that is called after the chain is finished. It213+is passed the list of return values as well as any parameters registered on the214+group.215+216+A command can return anything, including a function. Here's an example of that,217+where each subcommand creates a function that processes the input, then the218+result callback calls each function. The command takes a file, processes each219+line, then outputs it. If no subcommands are given, it outputs the contents220+of the file unchanged.221+222+```python223+@click.group(chain=True, invoke_without_command=True)224+@click.argument("fin", type=click.File("r"))225+def cli(fin):226+ pass227+228+@cli.result_callback()229+def process_pipeline(processors, fin):230+ iterator = (x.rstrip("\r\n") for x in input)231+232+ for processor in processors:233+ iterator = processor(iterator)234+235+ for item in iterator:236+ click.echo(item)237+238+@cli.command("upper")239+def make_uppercase():240+ def processor(iterator):241+ for line in iterator:242+ yield line.upper()243+ return processor244+245+@cli.command("lower")246+def make_lowercase():247+ def processor(iterator):248+ for line in iterator:249+ yield line.lower()250+ return processor251+252+@cli.command("strip")253+def make_strip():254+ def processor(iterator):255+ for line in iterator:256+ yield line.strip()257+ return processor258+```259+260+That's a lot in one go, so let's go through it step by step.261+262+1. The first thing is to make a {func}`group` that is chainable. In263+ addition to that we also instruct Click to invoke even if no264+ subcommand is defined. If this would not be done, then invoking an265+ empty pipeline would produce the help page instead of running the266+ result callbacks.267+2. The next thing we do is to register a result callback on our group.268+ This callback will be invoked with an argument which is the list of269+ all return values of all subcommands and then the same keyword270+ parameters as our group itself. This means we can access the input271+ file easily there without having to use the context object.272+3. In this result callback we create an iterator of all the lines in the273+ input file and then pass this iterator through all the returned274+ callbacks from all subcommands and finally we print all lines to275+ stdout.276+277+After that point we can register as many subcommands as we want and each278+subcommand can return a processor function to modify the stream of lines.279+280+One important thing of note is that Click shuts down the context after281+each callback has been run. This means that for instance file types282+cannot be accessed in the `processor` functions as the files will already283+be closed there. This limitation is unlikely to change because it would284+make resource handling much more complicated. For such it's recommended285+to not use the file type and manually open the file through286+{func}`open_file`.287+288+For a more complex example that also improves upon handling of the pipelines,289+see the [imagepipe example](https://github.com/pallets/click/tree/main/examples/imagepipe)290+in the Click repository. It implements a pipeline based image editing tool291+that has a nice internal structure.292+293+## Overriding Defaults294+295+By default, the default value for a parameter is pulled from the296+`default` flag that is provided when it's defined, but that's not the297+only place defaults can be loaded from. The other place is the298+{attr}`Context.default_map` (a dictionary) on the context. This allows299+defaults to be loaded from a configuration file to override the regular300+defaults.301+302+This is useful if you plug in some commands from another package but303+you're not satisfied with the defaults.304+305+The default map can be nested arbitrarily for each subcommand:306+307+```python308+309+ default_map = {310+ "debug": True, # default for a top level option311+ "runserver": {"port": 5000} # default for a subcommand312+ }313+```314+315+The default map can be provided when the script is invoked, or316+overridden at any point by commands. For instance, a top-level command317+could load the defaults from a configuration file.318+319+Example usage:320+321+```{eval-rst}322+.. click:example::323+324+ import click325+326+ @click.group()327+ def cli():328+ pass329+330+ @cli.command()331+ @click.option('--port', default=8000)332+ def runserver(port):333+ click.echo(f"Serving on http://127.0.0.1:{port}/")334+335+ if __name__ == '__main__':336+ cli(default_map={337+ 'runserver': {338+ 'port': 5000339+ }340+ })341+342+And in action:343+344+.. click:run::345+346+ invoke(cli, prog_name='cli', args=['runserver'], default_map={347+ 'runserver': {348+ 'port': 5000349+ }350+ })351+```352+353+## Context Defaults354+355+```{versionadded} 2.0356+```357+358+Starting with Click 2.0 you can override defaults for contexts not just359+when calling your script, but also in the decorator that declares a360+command. For instance given the previous example which defines a custom361+`default_map` this can also be accomplished in the decorator now.362+363+This example does the same as the previous example:364+365+```{eval-rst}366+.. click:example::367+368+ import click369+370+ CONTEXT_SETTINGS = dict(371+ default_map={'runserver': {'port': 5000}}372+ )373+374+ @click.group(context_settings=CONTEXT_SETTINGS)375+ def cli():376+ pass377+378+ @cli.command()379+ @click.option('--port', default=8000)380+ def runserver(port):381+ click.echo(f"Serving on http://127.0.0.1:{port}/")382+383+ if __name__ == '__main__':384+ cli()385+386+And again the example in action:387+388+.. click:run::389+390+ invoke(cli, prog_name='cli', args=['runserver'])391+```392+393+## Command Return Values394+395+```{versionadded} 3.0396+```397+398+One of the new introductions in Click 3.0 is the full support for return399+values from command callbacks. This enables a whole range of features400+that were previously hard to implement.401+402+In essence any command callback can now return a value. This return value403+is bubbled to certain receivers. One usecase for this has already been404+show in the example of {ref}`command-chaining` where it has been405+demonstrated that chained groups can have callbacks that process406+all return values.407+408+When working with command return values in Click, this is what you need to409+know:410+411+- The return value of a command callback is generally returned from the412+ {meth}`Command.invoke` method. The exception to this rule has to413+ do with {class}`Group`s:414+415+ - In a group the return value is generally the return value of the416+ subcommand invoked. The only exception to this rule is that the417+ return value is the return value of the group callback if it's418+ invoked without arguments and `invoke_without_command` is enabled.419+ - If a group is set up for chaining then the return value is a list420+ of all subcommands' results.421+ - Return values of groups can be processed through a422+ {attr}`Group.result_callback`. This is invoked with the423+ list of all return values in chain mode, or the single return424+ value in case of non chained commands.425+426+- The return value is bubbled through from the {meth}`Context.invoke`427+ and {meth}`Context.forward` methods. This is useful in situations428+ where you internally want to call into another command.429+430+- Click does not have any hard requirements for the return values and431+ does not use them itself. This allows return values to be used for432+ custom decorators or workflows (like in the command chaining433+ example).434+435+- When a Click script is invoked as command line application (through436+ {meth}`Command.main`) the return value is ignored unless the437+ `standalone_mode` is disabled in which case it's bubbled through.deleted:docs/commands.rst-428 removed
1-Advanced Groups and Context2-=============================3-4-.. currentmodule:: click5-6-In addition to the capabilities covered in the previous section, Groups have more advanced capabilities that leverage the Context.7-8-.. contents::9- :depth: 110- :local:11-12-Callback Invocation13--------------------14-15-For a regular command, the callback is executed whenever the command runs.16-If the script is the only command, it will always fire (unless a parameter17-callback prevents it. This for instance happens if someone passes18-``--help`` to the script).19-20-For groups, the situation looks different. In this case, the callback fires21-whenever a subcommand fires. What this means in practice is that an outer22-command runs when an inner command runs:23-24-.. click:example::25-26- @click.group()27- @click.option('--debug/--no-debug', default=False)28- def cli(debug):29- click.echo(f"Debug mode is {'on' if debug else 'off'}")30-31- @cli.command() # @cli, not @click!32- def sync():33- click.echo('Syncing')34-35-Here is what this looks like:36-37-.. click:run::38-39- invoke(cli, prog_name='tool.py')40- println()41- invoke(cli, prog_name='tool.py', args=['--debug', 'sync'])42-43-Nested Handling and Contexts44-----------------------------45-46-As you can see from the earlier example, the basic command group accepts a47-debug argument which is passed to its callback, but not to the sync48-command itself. The sync command only accepts its own arguments.49-50-This allows tools to act completely independent of each other, but how51-does one command talk to a nested one? The answer to this is the52-:class:`Context`.53-54-Each time a command is invoked, a new context is created and linked with the55-parent context. Normally, you can't see these contexts, but they are56-there. Contexts are passed to parameter callbacks together with the57-value automatically. Commands can also ask for the context to be passed58-by marking themselves with the :func:`pass_context` decorator. In that59-case, the context is passed as first argument.60-61-The context can also carry a program specified object that can be62-used for the program's purposes. What this means is that you can build a63-script like this:64-65-.. click:example::66-67- @click.group()68- @click.option('--debug/--no-debug', default=False)69- @click.pass_context70- def cli(ctx, debug):71- # ensure that ctx.obj exists and is a dict (in case `cli()` is called72- # by means other than the `if` block below)73- ctx.ensure_object(dict)74-75- ctx.obj['DEBUG'] = debug76-77- @cli.command()78- @click.pass_context79- def sync(ctx):80- click.echo(f"Debug is {'on' if ctx.obj['DEBUG'] else 'off'}")81-82- if __name__ == '__main__':83- cli(obj={})84-85-If the object is provided, each context will pass the object onwards to86-its children, but at any level a context's object can be overridden. To87-reach to a parent, ``context.parent`` can be used.88-89-In addition to that, instead of passing an object down, nothing stops the90-application from modifying global state. For instance, you could just flip91-a global ``DEBUG`` variable and be done with it.92-93-Decorating Commands94--------------------95-96-As you have seen in the earlier example, a decorator can change how a97-command is invoked. What actually happens behind the scenes is that98-callbacks are always invoked through the :meth:`Context.invoke` method99-which automatically invokes a command correctly (by either passing the100-context or not).101-102-This is very useful when you want to write custom decorators. For103-instance, a common pattern would be to configure an object representing104-state and then storing it on the context and then to use a custom105-decorator to find the most recent object of this sort and pass it as first106-argument.107-108-For instance, the :func:`pass_obj` decorator can be implemented like this:109-110-.. click:example::111-112- from functools import update_wrapper113-114- def pass_obj(f):115- @click.pass_context116- def new_func(ctx, *args, **kwargs):117- return ctx.invoke(f, ctx.obj, *args, **kwargs)118- return update_wrapper(new_func, f)119-120-The :meth:`Context.invoke` command will automatically invoke the function121-in the correct way, so the function will either be called with ``f(ctx,122-obj)`` or ``f(obj)`` depending on whether or not it itself is decorated with123-:func:`pass_context`.124-125-This is a very powerful concept that can be used to build very complex126-nested applications; see :ref:`complex-guide` for more information.127-128-.. _command-chaining:129-130-Command Chaining131-----------------132-133-It is useful to invoke more than one subcommand in one call. For example,134-``my-app validate build upload`` would invoke ``validate``, then ``build``, then135-``upload``. To implement this, pass ``chain=True`` when creating a group.136-137-.. click:example::138-139- @click.group(chain=True)140- def cli():141- pass142-143- @cli.command('validate')144- def validate():145- click.echo('validate')146-147- @cli.command('build')148- def build():149- click.echo('build')150-151-You can invoke it like this:152-153-.. click:run::154-155- invoke(cli, prog_name='my-app', args=['validate', 'build'])156-157-When using chaining, there are a few restrictions:158-159-- Only the last command may use ``nargs=-1`` on an argument, otherwise the160- parser will not be able to find further commands.161-- It is not possible to nest groups below a chain group.162-- On the command line, options must be specified before arguments for each163- command in the chain.164-- The :attr:`Context.invoked_subcommand` attribute will be ``'*'`` because the165- parser doesn't know the full list of commands that will run yet.166-167-.. _command-pipelines:168-169-Command Pipelines170-------------------171-172-When using chaining, a common pattern is to have each command process the173-result of the previous command.174-175-A straightforward way to do this is to use :func:`make_pass_decorator` to pass176-a context object to each command, and store and read the data on that object.177-178-.. click:example::179-180- pass_ns = click.make_pass_decorator(dict, ensure=True)181-182- @click.group(chain=True)183- @click.argument("name")184- @pass_ns185- def cli(ns, name):186- ns["name"] = name187-188- @cli.command189- @pass_ns190- def lower(ns):191- ns["name"] = ns["name"].lower()192-193- @cli.command194- @pass_ns195- def show(ns):196- click.echo(ns["name"])197-198-.. click:run::199-200- invoke(cli, prog_name="process", args=["Click", "show", "lower", "show"])201-202-Another way to do this is to collect data returned by each command, then process203-it at the end of the chain. Use the group's :meth:`~Group.result_callback`204-decorator to register a function that is called after the chain is finished. It205-is passed the list of return values as well as any parameters registered on the206-group.207-208-A command can return anything, including a function. Here's an example of that,209-where each subcommand creates a function that processes the input, then the210-result callback calls each function. The command takes a file, processes each211-line, then outputs it. If no subcommands are given, it outputs the contents212-of the file unchanged.213-214-.. code-block:: python215-216- @click.group(chain=True, invoke_without_command=True)217- @click.argument("fin", type=click.File("r"))218- def cli(fin):219- pass220-221- @cli.result_callback()222- def process_pipeline(processors, fin):223- iterator = (x.rstrip("\r\n") for x in input)224-225- for processor in processors:226- iterator = processor(iterator)227-228- for item in iterator:229- click.echo(item)230-231- @cli.command("upper")232- def make_uppercase():233- def processor(iterator):234- for line in iterator:235- yield line.upper()236- return processor237-238- @cli.command("lower")239- def make_lowercase():240- def processor(iterator):241- for line in iterator:242- yield line.lower()243- return processor244-245- @cli.command("strip")246- def make_strip():247- def processor(iterator):248- for line in iterator:249- yield line.strip()250- return processor251-252-That's a lot in one go, so let's go through it step by step.253-254-1. The first thing is to make a :func:`group` that is chainable. In255- addition to that we also instruct Click to invoke even if no256- subcommand is defined. If this would not be done, then invoking an257- empty pipeline would produce the help page instead of running the258- result callbacks.259-2. The next thing we do is to register a result callback on our group.260- This callback will be invoked with an argument which is the list of261- all return values of all subcommands and then the same keyword262- parameters as our group itself. This means we can access the input263- file easily there without having to use the context object.264-3. In this result callback we create an iterator of all the lines in the265- input file and then pass this iterator through all the returned266- callbacks from all subcommands and finally we print all lines to267- stdout.268-269-After that point we can register as many subcommands as we want and each270-subcommand can return a processor function to modify the stream of lines.271-272-One important thing of note is that Click shuts down the context after273-each callback has been run. This means that for instance file types274-cannot be accessed in the `processor` functions as the files will already275-be closed there. This limitation is unlikely to change because it would276-make resource handling much more complicated. For such it's recommended277-to not use the file type and manually open the file through278-:func:`open_file`.279-280-For a more complex example that also improves upon handling of the pipelines,281-see the `imagepipe example`_ in the Click repository. It implements a282-pipeline based image editing tool that has a nice internal structure.283-284-.. _imagepipe example: https://github.com/pallets/click/tree/main/examples/imagepipe285-286-287-Overriding Defaults288--------------------289-290-By default, the default value for a parameter is pulled from the291-``default`` flag that is provided when it's defined, but that's not the292-only place defaults can be loaded from. The other place is the293-:attr:`Context.default_map` (a dictionary) on the context. This allows294-defaults to be loaded from a configuration file to override the regular295-defaults.296-297-This is useful if you plug in some commands from another package but298-you're not satisfied with the defaults.299-300-The default map can be nested arbitrarily for each subcommand:301-302-.. code-block:: python303-304- default_map = {305- "debug": True, # default for a top level option306- "runserver": {"port": 5000} # default for a subcommand307- }308-309-The default map can be provided when the script is invoked, or310-overridden at any point by commands. For instance, a top-level command311-could load the defaults from a configuration file.312-313-Example usage:314-315-.. click:example::316-317- import click318-319- @click.group()320- def cli():321- pass322-323- @cli.command()324- @click.option('--port', default=8000)325- def runserver(port):326- click.echo(f"Serving on http://127.0.0.1:{port}/")327-328- if __name__ == '__main__':329- cli(default_map={330- 'runserver': {331- 'port': 5000332- }333- })334-335-And in action:336-337-.. click:run::338-339- invoke(cli, prog_name='cli', args=['runserver'], default_map={340- 'runserver': {341- 'port': 5000342- }343- })344-345-Context Defaults346-----------------347-348-.. versionadded:: 2.0349-350-Starting with Click 2.0 you can override defaults for contexts not just351-when calling your script, but also in the decorator that declares a352-command. For instance given the previous example which defines a custom353-``default_map`` this can also be accomplished in the decorator now.354-355-This example does the same as the previous example:356-357-.. click:example::358-359- import click360-361- CONTEXT_SETTINGS = dict(362- default_map={'runserver': {'port': 5000}}363- )364-365- @click.group(context_settings=CONTEXT_SETTINGS)366- def cli():367- pass368-369- @cli.command()370- @click.option('--port', default=8000)371- def runserver(port):372- click.echo(f"Serving on http://127.0.0.1:{port}/")373-374- if __name__ == '__main__':375- cli()376-377-And again the example in action:378-379-.. click:run::380-381- invoke(cli, prog_name='cli', args=['runserver'])382-383-384-Command Return Values385----------------------386-387-.. versionadded:: 3.0388-389-One of the new introductions in Click 3.0 is the full support for return390-values from command callbacks. This enables a whole range of features391-that were previously hard to implement.392-393-In essence any command callback can now return a value. This return value394-is bubbled to certain receivers. One usecase for this has already been395-show in the example of :ref:`command-chaining` where it has been396-demonstrated that chained groups can have callbacks that process397-all return values.398-399-When working with command return values in Click, this is what you need to400-know:401-402-- The return value of a command callback is generally returned from the403- :meth:`Command.invoke` method. The exception to this rule has to404- do with :class:`Group`\s:405-406- * In a group the return value is generally the return value of the407- subcommand invoked. The only exception to this rule is that the408- return value is the return value of the group callback if it's409- invoked without arguments and `invoke_without_command` is enabled.410- * If a group is set up for chaining then the return value is a list411- of all subcommands' results.412- * Return values of groups can be processed through a413- :attr:`Group.result_callback`. This is invoked with the414- list of all return values in chain mode, or the single return415- value in case of non chained commands.416-417-- The return value is bubbled through from the :meth:`Context.invoke`418- and :meth:`Context.forward` methods. This is useful in situations419- where you internally want to call into another command.420-421-- Click does not have any hard requirements for the return values and422- does not use them itself. This allows return values to be used for423- custom decorators or workflows (like in the command chaining424- example).425-426-- When a Click script is invoked as command line application (through427- :meth:`Command.main`) the return value is ignored unless the428- `standalone_mode` is disabled in which case it's bubbled through.