T6: Decompose CLI — main.py → 9 command files, config.py → config_cmd.py
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.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""Entry point приложения cf. Регистрирует все команды."""
|
||||
import sys
|
||||
|
||||
import typer
|
||||
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
except (AttributeError, OSError):
|
||||
pass
|
||||
|
||||
from infrastructure.cli.i18n import setup_i18n, t
|
||||
from infrastructure.cli.commands import (
|
||||
analyze,
|
||||
compare,
|
||||
config_cmd,
|
||||
export_xlsx,
|
||||
forecast,
|
||||
import_xlsx,
|
||||
info,
|
||||
init,
|
||||
scenario,
|
||||
whatif,
|
||||
)
|
||||
|
||||
setup_i18n()
|
||||
|
||||
app = typer.Typer(name="cf", help=t("app.help"))
|
||||
|
||||
# Команды верхнего уровня
|
||||
app.command(name="init")(init.init)
|
||||
app.command(name="forecast")(forecast.forecast)
|
||||
app.command(name="scenario")(scenario.scenario)
|
||||
app.command(name="whatif")(whatif.whatif)
|
||||
app.command(name="compare")(compare.compare)
|
||||
app.command(name="import-xlsx")(import_xlsx.import_xlsx)
|
||||
app.command(name="export-xlsx")(export_xlsx.export_xlsx)
|
||||
app.command(name="analyze")(analyze.analyze)
|
||||
app.command(name="info")(info.info)
|
||||
|
||||
# Под-приложение config
|
||||
app.add_typer(config_cmd.app, name="config")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
Reference in New Issue
Block a user