Skip to content

Commit

Permalink
Support for paths specification without subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 1, 2019
1 parent 04ce0c9 commit c50332c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ mod options {
/// Bytes - plain bytes without any formatting
#[structopt(short = "f", long = "format")]
pub format: Option<ByteFormat>,

/// One or more input files. If unset, we will assume the current directory
#[structopt(parse(from_os_str))]
pub input: Vec<PathBuf>,
}

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 12 additions & 4 deletions tests/stateless-journey.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
)
)

Expand Down

0 comments on commit c50332c

Please sign in to comment.