diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 12:18:05 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 12:18:05 +0530 |
commit | 04ce0c9312fb5e290d6fbaed8e9427bec3f3e1c6 (patch) | |
tree | 17d9b104f81649ab2644e2dea9431f0b6a10b933 /src/lib.rs | |
parent | 7dc718bd03f7f669638d87b4c5fee67700f045ca (diff) |
Compute the total if there are more than one paths
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -60,7 +60,10 @@ mod aggregate { paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> Result<WalkResult, Error> { let mut res = WalkResult::default(); + let mut total = 0; + let mut num_roots = 0; for path in paths.into_iter() { + num_roots += 1; let mut num_bytes = 0u64; for entry in options.iter_from_path(path.as_ref()) { match entry { @@ -81,15 +84,28 @@ mod aggregate { } } - writeln!( - out, - "{}\t{}", - options.format_bytes(num_bytes), - path.as_ref().display() - )?; + write_path(&mut out, &options, path, num_bytes)?; + total += num_bytes; + } + if num_roots > 1 { + write_path(&mut out, &options, Path::new("<TOTAL>"), total)?; } Ok(res) } + + fn write_path( + out: &mut impl io::Write, + options: &WalkOptions, + path: impl AsRef<Path>, + num_bytes: u64, + ) -> Result<(), io::Error> { + writeln!( + out, + "{}\t{}", + options.format_bytes(num_bytes), + path.as_ref().display() + ) + } } pub use aggregate::aggregate; |