Skip to content
Myr

Added support for passing through arguments to result callbacks

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 f92c4f4 · Browse files · 1 file+19 added−3 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+19 added−3 removed

  • other:+19 added−3 removed

1 file+19 added−3 removed

modified:click/core.py+19 added-3 removed
795 unmodified lines
796797 def resultcallback(self, replace=False):798 """Adds a result callback to the chain command. By default if a799 result callback is already registered this will chain them but800 this can be disabled with the `replace` parameter.800 this can be disabled with the `replace` parameter. The result801 callback is invoked with the return value of the subcommand802 (or the list of return values from all subcommands if chaining803 is enabled) as well as the parameters as they would be passed804 to the main callback.805806 Example::807808 @click.group()809 @click.option('-i', '--input', default=23)810 def cli(input):811 return 42812813 @cli.resultcallback()814 def process_result(result, input):815 return result + input816817 .. versionadded:: 3.0818819 :param replace: if set to `True` an already existing result820 callback will be removed.
2 unmodified lines
823 old_callback = self.result_callback824 if old_callback is None or replace:825 self.result_callback = f826 return f812 def function(value):813 return f(old_callback(value))827 def function(__value, *args, **kwargs):828 return f(old_callback(__value, *args, **kwargs),829 *args, **kwargs)830 self.result_callback = rv = update_wrapper(function, f)831 return rv832 return decorator833
676 unmodified lines