mirror of
https://codeberg.org/icewind/vmt-parser.git
synced 2026-06-03 12:04:06 +02:00
dir parsing test example
This commit is contained in:
parent
e6b54a8c8d
commit
4629d01d0f
3 changed files with 76 additions and 4 deletions
42
examples/dir.rs
Normal file
42
examples/dir.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use miette::{Context, IntoDiagnostic, Result};
|
||||
use std::env::args;
|
||||
use std::fs::read_to_string;
|
||||
use std::path::Path;
|
||||
use vmt_parser::from_str;
|
||||
use vmt_parser::material::Material;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut success = 0;
|
||||
let mut err = Vec::new();
|
||||
let dir = args().nth(1).expect("no path provided");
|
||||
for entry in WalkDir::new(dir)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
.filter(|e| e.file_name().to_str().unwrap_or_default().ends_with(".vmt"))
|
||||
{
|
||||
if let Err(e) = try_parse(entry.path()) {
|
||||
err.push(e);
|
||||
let e = try_parse(entry.path()).unwrap_err();
|
||||
println!("{:?}", e);
|
||||
} else {
|
||||
success += 1;
|
||||
println!("{}", entry.path().display());
|
||||
}
|
||||
}
|
||||
|
||||
println!("successfully parsed {success} files");
|
||||
println!("found errors in {} files", err.len());
|
||||
for e in err {
|
||||
println!("{:?}", e);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn try_parse(path: &Path) -> Result<Material> {
|
||||
let raw = read_to_string(path)
|
||||
.into_diagnostic()
|
||||
.wrap_err_with(|| format!("failed to read {}", path.display()))?;
|
||||
from_str(&raw).into_diagnostic()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue