Python click.pass_obj() Examples

The following are 4 code examples of click.pass_obj(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module click , or try the search function .
Example #1
Source File: __init__.py    From srep with GNU General Public License v3.0 5 votes vote down vote up
def packargs(func):
    import click
    return click.pass_obj(_packargs(func)) 
Example #2
Source File: client.py    From us-pycon-2019-tutorial with Apache License 2.0 5 votes vote down vote up
def async_cmd(func: Callable[..., Awaitable[None]]) -> Callable[..., None]:
    @functools.wraps(func)
    def inner(root: Root, **kwargs: Any) -> None:
        try:
            return asyncio.run(func(root, **kwargs))
        except Exception as exc:
            if root.show_traceback:
                raise
            else:
                click.echo(f"Error: {exc}")

    inner = click.pass_obj(inner)
    return inner 
Example #3
Source File: 01-client.py    From us-pycon-2019-tutorial with Apache License 2.0 5 votes vote down vote up
def async_cmd(func: Callable[..., Awaitable[None]]) -> Callable[..., None]:
    @functools.wraps(func)
    def inner(root: Root, **kwargs: Any) -> None:
        try:
            return asyncio.run(func(root, **kwargs))
        except Exception as exc:
            if root.show_traceback:
                raise
            else:
                click.echo(f"Error: {exc}")

    inner = click.pass_obj(inner)
    return inner 
Example #4
Source File: cli.py    From cachebrowser with MIT License 4 votes vote down vote up
def forward_to_api(route, params=None):
    def wrapper(func):
        @click.pass_obj
        def inner(context, **kwargs):
            request_params = params.copy() if params else {}
            request_params.update(kwargs)
            request = APIRequest(route, request_params)
            request.reply = partial(func, context)
            api.handle_api_request(context, request)

        return update_wrapper(inner, func)

    return wrapper