Files
mtgc/crates/mtgc-core/src/bin/ingest.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

//! CLI: build reference.db from Scryfall bulk data.
//!
//! Usage: `mtgc-ingest [path/to/reference.db]` (defaults to ./reference.db)
use std::path::PathBuf;
use std::process::ExitCode;
use mtgc_core::ingest::CancelToken;
fn main() -> ExitCode {
let dest = std::env::args()
.nth(1)
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("reference.db"));
eprintln!("Building reference db at {}", dest.display());
let cancel = CancelToken::new();
let built = mtgc_core::ingest::build_reference_db(&dest, &cancel, |p| {
eprintln!(" [{}] {:.1}% {}", p.stage, p.overall_percent, p.message)
})
.and_then(|(tmp, stats)| {
mtgc_core::ingest::install_reference_db(&tmp, &dest)?;
Ok(stats)
});
match built {
Ok(stats) => {
eprintln!(
"Done: {} oracle cards, {} printings.",
stats.oracle_cards, stats.printings
);
ExitCode::SUCCESS
}
Err(e) => {
eprintln!("Ingest failed: {e}");
ExitCode::FAILURE
}
}
}