From c50332cead2688e40de192e1b47e50a662763a78 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 1 Jun 2019 12:23:11 +0530 Subject: [PATCH] Support for paths specification without subcommand --- src/main.rs | 14 +++++++++++++- tests/stateless-journey.sh | 16 ++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3f96451a..452d739d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,10 @@ mod options { /// Bytes - plain bytes without any formatting #[structopt(short = "f", long = "format")] pub format: Option, + + /// One or more input files. If unset, we will assume the current directory + #[structopt(parse(from_os_str))] + pub input: Vec, } #[derive(Debug, StructOpt)] @@ -77,7 +81,15 @@ fn run() -> Result<(), Error> { }; let res = match opt.command { Some(Aggregate { input }) => dua::aggregate(stdout_locked, walk_options, input), - None => dua::aggregate(stdout_locked, walk_options, vec![PathBuf::from(".")]), + None => dua::aggregate( + stdout_locked, + walk_options, + if opt.input.len() == 0 { + vec![PathBuf::from(".")] + } else { + opt.input + }, + ), }?; if res.num_errors > 0 { diff --git a/tests/stateless-journey.sh b/tests/stateless-journey.sh index 60f0586c..a6e0fa5c 100755 --- a/tests/stateless-journey.sh +++ b/tests/stateless-journey.sh @@ -24,10 +24,18 @@ SUCCESSFULLY=0 ) ls (with "multiple given paths" - 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" a . . dir ./dir/ ./dir/sub - } + (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 no 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" . . dir ./dir/ ./dir/sub + } + ) ) )