diff options
author | abazylewicz <abazylewicz@gmail.com> | 2019-12-01 12:10:33 +0100 |
---|---|---|
committer | Abin Simon <abinsimon10@gmail.com> | 2019-12-05 11:43:01 +0530 |
commit | 939e9008bb9eae480ae778dc07105e441ae8bef5 (patch) | |
tree | 017ca7d3d7a30f1a7332be722cca8fb6f603cf26 /src | |
parent | d299073eed88ad5d0b861dcc8498699a2b844f21 (diff) |
Allow usage of multiple 'depth' arguments
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 1 | ||||
-rw-r--r-- | src/flags.rs | 26 |
2 files changed, 25 insertions, 2 deletions
@@ -104,6 +104,7 @@ pub fn build() -> App<'static, 'static> { .arg( Arg::with_name("depth") .long("depth") + .multiple(true) .takes_value(true) .value_name("num") .help("Stop recursing into directories after reaching specified depth"), diff --git a/src/flags.rs b/src/flags.rs index 3c9c0d1..f745ef4 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -69,7 +69,7 @@ impl Flags { Layout::Grid }; let recursive = matches.is_present("recursive"); - let recursion_depth = match matches.value_of("depth") { + let recursion_depth = match matches.values_of("depth") { Some(str) if recursive || layout @@ -77,7 +77,7 @@ impl Flags { long: matches.is_present("long"), } => { - match str.parse::<usize>() { + match str.last().unwrap().parse::<usize>() { Ok(val) => val, Err(_) => { return Err(Error::with_description( @@ -359,4 +359,26 @@ mod test { assert!(res.is_err()); assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); } + + #[test] + fn test_duplicate_depth() { + let matches = app::build() + .get_matches_from_safe(vec!["lsd", "--tree", "--depth", "1", "--depth", "2"]) + .unwrap(); + let res = Flags::from_matches(&matches); + + assert!(res.is_ok()); + assert_eq!(res.unwrap().recursion_depth, 2); + } + + #[test] + fn test_missing_depth() { + let matches = app::build() + .get_matches_from_safe(vec!["lsd", "--tree"]) + .unwrap(); + let res = Flags::from_matches(&matches); + + assert!(res.is_ok()); + assert_eq!(res.unwrap().recursion_depth, usize::max_value()); + } } |