Files
nifodea/infrastructure/cli/commands/analyze.py
T
oqyude f66a762796 D3: убрать мёртвые typer.Typer() из 9 модулей команд
Регистрация CLI идёт через infrastructure/cli/app.py:30-38, где вешается
«сырая» функция. Поэтому в каждом из 9 одно-командных модулей стоял свой
typer.Typer() с декоратором @app.command() — регистрация, которая никогда
не читалась. Убраны:

  commands/analyze.py, compare.py, export_xlsx.py, forecast.py,
  import_xlsx.py, info.py, init.py, scenario.py, whatif.py

commands/config_cmd.py НЕ тронут: его app — настоящий sub-typer,
регистрируемый в app.py:41.

Страховка (написана и проверена ДО правки, проходит и после):
- новый tests/test_cli_contract.py — инвариант поверхности CLI: 9 команд
  верхнего уровня + 19 подкоманд config, у каждой leaf-команды есть
  callback, дефолт export-xlsx = "exports/forecast.xlsx". Тест защищает
  и будущий рефакторинг D25 (разбиение config_cmd.py на пакет).
- сверка вывода `cf --help`, `cf config --help`, `cf export-xlsx --help`,
  `cf forecast --help` с pristine-копией HEAD — побайтово идентично.

Проверка: 81/81 тестов зелёные (75 + 6 новых), ruff check . — All checks passed.
2026-10-23 18:29:49 +03:00

27 lines
1.1 KiB
Python

"""cf analyze — AI-анализ финансовой модели (заглушка)."""
import typer
from infrastructure.cli.i18n import t
from infrastructure.cli.services import build_services, console, load_model, resolve_currency
CURRENCY_OPTION = typer.Option(None, "--currency", "-c", help=t("cmd.forecast.opt.currency"))
def analyze(
months: int = typer.Option(12, "--months", "-m", help=t("cmd.analyze.opt.months")),
currency: str | None = CURRENCY_OPTION,
) -> None:
"""AI-анализ финансовой модели"""
model = load_model()
target_curr, _ = resolve_currency(model, currency)
_, _, assistant, _ = build_services(model)
assistant.display_currency = target_curr
result = assistant.analyze(months)
console.print(f"[bold]{t('cmd.analyze.title.prompt')}:[/bold]")
console.print(result["prompt"][:500] + "...\n")
console.print(f"[bold]{t('cmd.analyze.title.summary')}:[/bold]")
console.print(t("cmd.analyze.base_currency", currency=model.base_currency))
console.print(f"\n[yellow]{t('cmd.analyze.stub')}[/yellow]")