28 lines
1.0 KiB
Rust
28 lines
1.0 KiB
Rust
//! Read and validate a saved acceptance fixture without rewriting its source.
|
|||
|
|
//! cargo run --locked -p oa-core --example attachment_snapshot -- input.arcadia output.json
|
||
|
|
use oa_core::{persistence, validate_candidate};
|
||
|
|
use std::{fs::OpenOptions, io::Write, path::Path};
|
||
|
|
|
||
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||
|
|
let args: Vec<_> = std::env::args_os().skip(1).collect();
|
||
|
|
if args.len() != 2 {
|
||
|
|
return Err("Expected input source/JSON and a new output JSON path".into());
|
||
|
|
}
|
||
|
|
let project = persistence::load(Path::new(&args[0]))?;
|
||
|
|
validate_candidate(&project)?;
|
||
|
|
let bytes = serde_json::to_vec_pretty(&project)?;
|
||
|
|
let mut output = OpenOptions::new()
|
||
|
|
.write(true)
|
||
|
|
.create_new(true)
|
||
|
|
.open(&args[1])?;
|
||
|
|
output.write_all(&bytes)?;
|
||
|
|
output.write_all(b"\n")?;
|
||
|
|
output.sync_all()?;
|
||
|
|
println!(
|
||
|
|
"Validated {} objects and {} views; saved a complete Project snapshot",
|
||
|
|
project.identities().len(),
|
||
|
|
project.diagrams.len()
|
||
|
|
);
|
||
|
|
Ok(())
|
||
|
|
}
|