Split infrastructure/cli/: - main.py (330 LOC) → 9 files in infrastructure/cli/commands/: * init.py, forecast.py, scenario.py, whatif.py, compare.py * import_xlsx.py, export_xlsx.py, analyze.py, info.py - config.py (428 LOC) → commands/config_cmd.py (15 sub-commands) - main.py → app.py (entry point: registers all commands) - New: paths.py (MODEL_PATH, DATA_DIR) - New: services.py (composition root + helpers: load_model, save_model, build_services, resolve_currency, convert_value, fmt_amount) - cli/__init__.py (empty) удалён Each command module: <100 LOC. pyproject.toml: cf = infrastructure.cli.app:app tests/test_cli.py: import обновлён на infrastructure.cli.app CLI behavior идентично, все команды работают. Tests: 67/67 pass.
24 lines
756 B
Python
24 lines
756 B
Python
"""cf export-xlsx — экспорт модели в Excel."""
|
|
import typer
|
|
|
|
from infrastructure.cli.i18n import t
|
|
from infrastructure.cli.services import console, load_model
|
|
from infrastructure.repositories import ExcelRepository, ExcelRepositoryError
|
|
|
|
app = typer.Typer()
|
|
_repo = ExcelRepository()
|
|
|
|
|
|
@app.command(name="export-xlsx")
|
|
def export_xlsx(
|
|
path: str = typer.Argument("exports/forecast.xlsx", help=t("cmd.export.arg.path")),
|
|
) -> None:
|
|
"""Экспорт модели в Excel"""
|
|
model = load_model()
|
|
try:
|
|
_repo.save(model, path)
|
|
console.print(t("cmd.export.ok", path=path))
|
|
except ExcelRepositoryError as e:
|
|
console.print(f"[red]{t('cmd.export.err', error=str(e))}[/red]")
|
|
raise typer.Exit(1)
|