Files
portfolio-hub/app/cli/main.py
T
2026-04-23 09:56:08 +00:00

62 lines
1.8 KiB
Python

"""Typer entrypoint for PortfolioHub."""
from __future__ import annotations
from dataclasses import dataclass
from typing import Callable
import typer
from rich.console import Console
from app.cli.commands.health import register_health_commands
from app.cli.commands.service_tokens import token_app
from app.cli.commands.portfolio import portfolio_app
from app.cli.commands.strategy import strategy_app
from app.cli.commands.user import user_app
from app.core.config import Settings, get_settings
from app.repositories.factory import get_portfolio_repository_from_settings
from app.repositories.portfolio_repository import PortfolioRepository
@dataclass
class AppContext:
settings: Settings
output_format: str
console: Console
repository_factory: Callable[[Settings], PortfolioRepository]
def create_app(
*,
settings_factory: Callable[[], Settings] = get_settings,
repository_factory: Callable[[Settings], PortfolioRepository] = get_portfolio_repository_from_settings,
) -> typer.Typer:
app = typer.Typer(help="PortfolioHub command line interface.", no_args_is_help=True)
@app.callback()
def main_callback(
ctx: typer.Context,
output_format: str = typer.Option("table", "--format", help="Output format: table or json."),
) -> None:
settings = settings_factory()
console = Console(no_color=True, width=160)
ctx.obj = AppContext(
settings=settings,
output_format=output_format,
console=console,
repository_factory=repository_factory,
)
app.add_typer(portfolio_app, name="portfolio")
app.add_typer(strategy_app, name="strategy")
app.add_typer(user_app, name="user")
app.add_typer(token_app, name="service-token")
register_health_commands(app)
return app
app = create_app()
def main() -> None:
app()