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