Регистрация 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.
46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""cf compare — сравнить все сценарии."""
|
|
import typer
|
|
from rich.table import Table
|
|
|
|
from infrastructure.cli.i18n import t
|
|
from infrastructure.cli.services import (
|
|
build_services,
|
|
console,
|
|
convert_value,
|
|
fmt_amount,
|
|
load_model,
|
|
resolve_currency,
|
|
)
|
|
|
|
CURRENCY_OPTION = typer.Option(None, "--currency", "-c", help=t("cmd.forecast.opt.currency"))
|
|
|
|
|
|
def compare(
|
|
months: int = typer.Option(12, "--months", "-m", help=t("cmd.compare.opt.months")),
|
|
currency: str | None = CURRENCY_OPTION,
|
|
) -> None:
|
|
"""Сравнить все сценарии"""
|
|
model = load_model()
|
|
target_curr, symbol = resolve_currency(model, currency)
|
|
_, scenario_service, _, converter = build_services(model)
|
|
base_curr = model.base_currency
|
|
results = scenario_service.compare(months)
|
|
|
|
table = Table(title=t("cmd.compare.title", currency=target_curr))
|
|
table.add_column(t("cmd.compare.col.scenario"), style="cyan")
|
|
table.add_column(t("cmd.forecast.col.balance"), justify="right")
|
|
table.add_column(t("cmd.forecast.col.income"), justify="right")
|
|
table.add_column(t("cmd.forecast.col.expenses"), justify="right")
|
|
|
|
for name, r in results.items():
|
|
b = convert_value(converter, r["total_balance"], base_curr, target_curr)
|
|
i = convert_value(converter, r["total_income"], base_curr, target_curr)
|
|
e = convert_value(converter, r["total_expenses"], base_curr, target_curr)
|
|
table.add_row(
|
|
name,
|
|
fmt_amount(b, target_curr, symbol),
|
|
fmt_amount(i, target_curr, symbol),
|
|
fmt_amount(e, target_curr, symbol),
|
|
)
|
|
console.print(table)
|