use fhir_sqlite_gen::assets;
fn main() -> std::process::ExitCode {
let check = std::env::args().any(|a| a == "--check");
let Some(defs) = assets::definitions_root() else {
eprintln!(
"no FHIR definitions found. Set {} or check out the model family \
at fhir/doc/fhir-specifications.",
assets::ENV_SPEC_DIR
);
return std::process::ExitCode::from(2);
};
let out = assets::assets_root();
match assets::regenerate(&defs, &out, !check) {
Err(e) => {
eprintln!("regen-assets: {e}");
std::process::ExitCode::FAILURE
}
Ok(arts) => {
let mut drifted = 0;
for a in &arts {
let state = match (&a.previous_sha256, a.is_current()) {
(None, _) => "NEW",
(Some(_), true) => "ok",
(Some(_), false) => {
drifted += 1;
"DRIFTED"
}
};
println!(" {state:<8} {} {}", &a.sha256[..16], a.name);
}
if check && drifted > 0 {
eprintln!(
"\n{drifted} asset(s) differ from what this tree generates (G2.2).\n\
The committed map is not the output of this generator. Run without \
--check to regenerate, and treat the result as a data migration \
(L12, O10.4a) rather than a file edit."
);
return std::process::ExitCode::FAILURE;
}
if !check {
println!("\nwrote {} artifact(s) + CHECKSUMS.txt", arts.len());
}
std::process::ExitCode::SUCCESS
}
}
}