d
This commit is contained in:
29
cli.py
29
cli.py
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user