This commit is contained in:
2026-02-12 17:19:24 -08:00
parent ccadea0576
commit a92a7fdc7d
8 changed files with 1132 additions and 39 deletions

29
cli.py
View File

@@ -375,6 +375,35 @@ def search(
typer.echo("No cards matched that filter.")
raise typer.Exit(code=0)
@app.command("import-db")
def import_db(
file: Path = typer.Argument(..., help="CSV or XLSX file to import"),
table: str = typer.Option(..., "--table", "-t", help="Target table to import into"),
sheet: Optional[str] = typer.Option(None, "--sheet", help="Excel sheet name (optional)"),
delimiter: str = typer.Option(",", "--delimiter", "-d", help="CSV delimiter (default ',')"),
db_path: Optional[Path] = typer.Option(None, "--db", help="Path to target SQLite DB"),
) -> None:
"""Import CSV or Excel data into the project's DB tables.
Examples:
tarot import-db angels.xlsx --table card_angels
tarot import-db angels.csv --table card_angels --delimiter ','
"""
try:
from tarot.db_import import import_file
except Exception as exc: # pragma: no cover - import errors bubble up in tests
typer.echo(f"Error loading import helper: {exc}")
raise typer.Exit(code=1)
try:
res = import_file(file, table, db_path=db_path, sheet=sheet, delimiter=delimiter)
except Exception as exc: # pragma: no cover - errors will be surfaced for visibility
typer.echo(f"Import failed: {exc}")
raise typer.Exit(code=1)
typer.echo(f"Inserted: {res.inserted}; Skipped: {res.skipped}; Updated: {res.updated}")
def _doc(obj: Any, fallback: str) -> str:
return inspect.getdoc(obj) or fallback