Files
Birthday-Pool-Bot/birthday_pool_bot/notifications/cli.py
2026-01-15 09:47:43 +03:00

45 lines
1.0 KiB
Python

import asyncio
import typer
from .service import NotificationsService
from .settings import NotificationsSettings
def callback(ctx: typer.Context):
ctx.obj["settings"] = ctx.obj["settings"].notifications
def run(ctx: typer.Context):
settings: NotificationsSettings = ctx.obj["settings"]
repositories_container: RepositoriesContainer = ctx.obj["repositories_container"]
service = NotificationsService(
settings=settings,
repositories_container=repositories_container,
)
asyncio.run(service.run())
def run_once(ctx: typer.Context):
settings: NotificationsSettings = ctx.obj["settings"]
repositories_container: RepositoriesContainer = ctx.obj["repositories_container"]
service = NotificationsService(
settings=settings,
repositories_container=repositories_container,
)
asyncio.run(service.send_notifications())
def get_cli() -> typer.Typer:
cli = typer.Typer()
cli.callback()(callback)
cli.command(name="run")(run)
cli.command(name="run-once")(run_once)
return cli