Coverage for src \ truenex_memory \ export \ __main__.py: 0%
19 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 10:21 +0200
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-19 10:21 +0200
1"""Command-line entry point for JSON export/import helpers."""
3from __future__ import annotations
5import json
6from pathlib import Path
7from typing import Annotated
9import typer
11from truenex_memory.export import export_json, import_json
13app = typer.Typer(help="Local JSON export/import utilities.")
16@app.command("export")
17def export_command(
18 source: Annotated[Path, typer.Argument(help="JSON file containing a list of records.")],
19 destination: Annotated[Path, typer.Argument(help="Export file to write.")],
20) -> None:
21 """Wrap a local records JSON file in the Truenex export envelope."""
23 records = json.loads(source.read_text(encoding="utf-8"))
24 if not isinstance(records, list):
25 raise typer.BadParameter("source must contain a JSON list of record objects")
26 payload = export_json(records, destination)
27 typer.echo(json.dumps({"destination": str(destination), "records": len(payload["records"])}, sort_keys=True))
30@app.command("import")
31def import_command(
32 source: Annotated[Path, typer.Argument(help="Export file to read.")],
33) -> None:
34 """Print records from a Truenex export file as JSON."""
36 typer.echo(json.dumps(import_json(source)["records"], indent=2, sort_keys=True))
39if __name__ == "__main__":
40 app()