diff --git a/src/format.rs b/src/format.rs index 77103c8..a03f059 100644 --- a/src/format.rs +++ b/src/format.rs @@ -24,7 +24,7 @@ pub fn string( pub fn file( config: &crate::config::Config, path: String, -) -> std::io::Result<()> { +) -> std::io::Result { use std::io::Write; let input = std::fs::read_to_string(&path)?; @@ -34,9 +34,10 @@ pub fn file( let output = crate::format::string(config, path.clone(), input); let output_bytes = output.as_bytes(); - if input_bytes != output_bytes { + let changed = input_bytes != output_bytes; + if changed { std::fs::File::create(path)?.write_all(output_bytes)?; } - Ok(()) + Ok(changed) } diff --git a/src/main.rs b/src/main.rs index f03dfda..3d95dc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,17 +14,25 @@ fn main() -> std::io::Result<()> { eprintln!("Formatting {} files.", paths.len()); - for result in paths + let (results, errors): (Vec<_>, Vec<_>) = paths .par_iter() - .map(|path| -> std::io::Result<()> { - eprintln!("Formatting: {}", &path); - alejandra::format::file(&config, path.to_string())?; - Ok(()) + .map(|path| -> std::io::Result { + alejandra::format::file(&config, path.to_string()).map( + |changed| { + if changed { + eprintln!("Formatted: {}", &path); + } + changed + }, + ) }) - .collect::>>() - { - result?; - } + .partition(Result::is_ok); + eprintln!( + "Errors/Changed/Formatted: {}/{}/{}", + errors.len(), + results.into_iter().map(Result::unwrap).filter(|&x| x).count(), + paths.len() + ); } None => { eprintln!("Formatting stdin.");