Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /mardiros_fastlife /src /fastlife /config /cli_command.py
| """ | |
| Configure views using a decorator. | |
| A simple usage: | |
| ```python | |
| from typing import Annotated | |
| from fastapi import Response | |
| from fastlife import Template, template, view_config | |
| @view_config("hello_world", "/", methods=["GET"]) | |
| async def hello_world( | |
| template: Annotated[Template, template("HelloWorld.jinja")], | |
| ) -> Response: | |
| return template() | |
| ``` | |
| """ | |
| from typing import Any | |
| from typer.core import TyperCommand | |
| from typer.models import Default | |
| from fastlife.adapters.tamahagane import RegistryHub, th_attach | |
| from fastlife.adapters.typer.model import CLICommand, CLIHook | |
| def cli_command( | |
| name: str | None = None, | |
| *, | |
| cls: type[TyperCommand] | None = None, | |
| context_settings: dict[Any, Any] | None = None, | |
| help: str | None = None, | |
| epilog: str | None = None, | |
| short_help: str | None = None, | |
| options_metavar: str | None = None, | |
| add_help_option: bool = True, | |
| no_args_is_help: bool = False, | |
| hidden: bool = False, | |
| deprecated: bool = False, | |
| rich_help_panel: str | None = Default(None), | |
| ) -> CLIHook: | |
| """ | |
| A decorator function to register a websocket view in the | |
| {class}`Configurator <fastlife.config.configurator.GenericConfigurator>` | |
| while scaning a module using {func}`include | |
| <fastlife.config.configurator.GenericConfigurator.include>`. | |
| :return: the configuration callback. | |
| """ | |
| command_name = name | |
| def configure( | |
| wrapped: CLIHook, | |
| ) -> CLIHook: | |
| def callback(registry: RegistryHub) -> None: | |
| registry.fastlife.add_cli_command( | |
| CLICommand( | |
| hook=wrapped, | |
| name=command_name, | |
| cls=cls, | |
| context_settings=context_settings, | |
| help=help, | |
| epilog=epilog, | |
| short_help=short_help, | |
| options_metavar=options_metavar, | |
| add_help_option=add_help_option, | |
| no_args_is_help=no_args_is_help, | |
| hidden=hidden, | |
| deprecated=deprecated, | |
| rich_help_panel=rich_help_panel, | |
| ) | |
| ) | |
| th_attach(wrapped, callback) | |
| return wrapped | |
| return configure | |
Xet Storage Details
- Size:
- 2.25 kB
- Xet hash:
- 69a67df8d834a737325293e7808fc3197e1d1213d5e4639b002e649d0750723d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.