1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 21:17:45 +00:00

Print stats when formatting trees

This commit is contained in:
Tom Bereknyei 2022-02-19 21:02:03 -05:00 committed by Kevin Amado
parent 6a259da3d9
commit 00f483212d
2 changed files with 21 additions and 12 deletions

View file

@ -24,7 +24,7 @@ pub fn string(
pub fn file( pub fn file(
config: &crate::config::Config, config: &crate::config::Config,
path: String, path: String,
) -> std::io::Result<()> { ) -> std::io::Result<bool> {
use std::io::Write; use std::io::Write;
let input = std::fs::read_to_string(&path)?; 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 = crate::format::string(config, path.clone(), input);
let output_bytes = output.as_bytes(); 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)?; std::fs::File::create(path)?.write_all(output_bytes)?;
} }
Ok(()) Ok(changed)
} }

View file

@ -14,17 +14,25 @@ fn main() -> std::io::Result<()> {
eprintln!("Formatting {} files.", paths.len()); eprintln!("Formatting {} files.", paths.len());
for result in paths let (results, errors): (Vec<_>, Vec<_>) = paths
.par_iter() .par_iter()
.map(|path| -> std::io::Result<()> { .map(|path| -> std::io::Result<bool> {
eprintln!("Formatting: {}", &path); alejandra::format::file(&config, path.to_string()).map(
alejandra::format::file(&config, path.to_string())?; |changed| {
Ok(()) if changed {
eprintln!("Formatted: {}", &path);
}
changed
},
)
}) })
.collect::<Vec<std::io::Result<()>>>() .partition(Result::is_ok);
{ eprintln!(
result?; "Errors/Changed/Formatted: {}/{}/{}",
} errors.len(),
results.into_iter().map(Result::unwrap).filter(|&x| x).count(),
paths.len()
);
} }
None => { None => {
eprintln!("Formatting stdin."); eprintln!("Formatting stdin.");