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:
parent
6a259da3d9
commit
00f483212d
2 changed files with 21 additions and 12 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -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.");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue