diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 12:43:00 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 12:43:52 +0530 |
commit | 961b743773da2a5112bd4ab70554c50b03ded3ad (patch) | |
tree | 08bc22433014e503e3bee1ffd86ae0be3cb48c5b | |
parent | c1cbcf355755fbd1ca6124cdba3b8e361a7bebf2 (diff) |
Add --no-total option
-rw-r--r-- | src/lib.rs | 11 | ||||
-rw-r--r-- | src/main.rs | 9 | ||||
-rw-r--r-- | tests/snapshots/success-no-arguments-multiple-input-paths-no-total | 5 | ||||
-rwxr-xr-x | tests/stateless-journey.sh | 18 |
4 files changed, 34 insertions, 9 deletions
@@ -58,6 +58,7 @@ mod aggregate { pub fn aggregate( mut out: impl io::Write, options: WalkOptions, + compute_total: bool, paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> Result<WalkResult, Error> { let mut res = WalkResult::default(); @@ -90,8 +91,14 @@ mod aggregate { total += num_bytes; res.num_errors += num_errors; } - if num_roots > 1 { - write_path(&mut out, &options, Path::new("total"), total, res.num_errors)?; + if num_roots > 1 && compute_total { + write_path( + &mut out, + &options, + Path::new("total"), + total, + res.num_errors, + )?; } Ok(res) } diff --git a/src/main.rs b/src/main.rs index 32154c4..57070be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,9 @@ mod options { /// Aggregrate the consumed space of one or more directories or files #[structopt(name = "aggregate", alias = "a")] Aggregate { + /// If set, no total column will be computed for multiple inputs + #[structopt(long = "no-total")] + no_total: bool, /// One or more input files. If unset, we will assume the current directory #[structopt(parse(from_os_str))] input: Vec<PathBuf>, @@ -69,7 +72,6 @@ mod options { } fn run() -> Result<(), Error> { - use io::Write; use options::Command::*; let opt: options::Args = options::Args::from_args(); @@ -80,10 +82,13 @@ fn run() -> Result<(), Error> { format: opt.format.map(Into::into).unwrap_or(ByteFormat::Metric), }; let res = match opt.command { - Some(Aggregate { input }) => dua::aggregate(stdout_locked, walk_options, input), + Some(Aggregate { input, no_total }) => { + dua::aggregate(stdout_locked, walk_options, !no_total, input) + } None => dua::aggregate( stdout_locked, walk_options, + true, if opt.input.len() == 0 { vec![PathBuf::from(".")] } else { diff --git a/tests/snapshots/success-no-arguments-multiple-input-paths-no-total b/tests/snapshots/success-no-arguments-multiple-input-paths-no-total new file mode 100644 index 0000000..6ca39e6 --- /dev/null +++ b/tests/snapshots/success-no-arguments-multiple-input-paths-no-total @@ -0,0 +1,5 @@ +1.26 MB . +1.26 MB . +1.26 MB dir +1.26 MB ./dir/ +256.00 KB ./dir/sub
\ No newline at end of file diff --git a/tests/stateless-journey.sh b/tests/stateless-journey.sh index 95886d2..bd31903 100755 --- a/tests/stateless-journey.sh +++ b/tests/stateless-journey.sh @@ -25,11 +25,19 @@ WITH_FAILURE=1 ) ls (with "multiple given paths" - (when "specifying a subcommand" - it "produces a human-readable (metric) aggregate of the current directory, with total" && { - WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths" \ - expect_run ${SUCCESSFULLY} "$exe" aggregate . . dir ./dir/ ./dir/sub - } + (when "specifying the 'aggregate' subcommand" + (with "no option to adjust the total" + it "produces a human-readable (metric) aggregate of the current directory, with total" && { + WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths" \ + expect_run ${SUCCESSFULLY} "$exe" aggregate . . dir ./dir/ ./dir/sub + } + ) + (with "the --no-total option set" + it "produces a human-readable (metric) aggregate of the current directory, without total" && { + WITH_SNAPSHOT="$snapshot/success-no-arguments-multiple-input-paths-no-total" \ + expect_run ${SUCCESSFULLY} "$exe" aggregate --no-total . . dir ./dir/ ./dir/sub + } + ) ) (when "specifying no subcommand" it "produces a human-readable (metric) aggregate of the current directory, with total" && { |