1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +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(
config: &crate::config::Config,
path: String,
) -> std::io::Result<()> {
) -> std::io::Result<bool> {
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)
}

View file

@ -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<bool> {
alejandra::format::file(&config, path.to_string()).map(
|changed| {
if changed {
eprintln!("Formatted: {}", &path);
}
changed
},
)
})
.collect::<Vec<std::io::Result<()>>>()
{
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.");