From 1cdef5fe96eb60bfe8c66f7e08b6bd5c221cdc20 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 10 Dec 2020 23:37:06 -0700 Subject: [PATCH] use existing display and layout --- CHANGELOG.md | 2 +- src/core.rs | 31 +++++++++++++++---------------- src/flags/display.rs | 14 +------------- src/meta/mod.rs | 10 ++++++---- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d247c4e..658996a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add support for `--extensionsort` `-X` from [aldhsu](https://github.com/aldhsu) - Add support for `--versionsort` `-v` from [zwpaper](https://github.com/zwpaper) - Add support for config symlink arrow from [zwpaper](https://github.com/zwpaper) [#409](https://github.com/Peltoche/lsd/issues/409) -- Implement `--tree -d`, analogous to `tree -d` from [0jdxt](https://github.com/0jdxt) +- Implement `--tree -d`, analogous to `tree -d` from [0jdxt](https://github.com/0jdxt) and [Utah Rust](https://github.com/utah-rust) ### Changed - Use last sort flag for sort field from [meain](https://github.com/meain) ### Fixed diff --git a/src/core.rs b/src/core.rs index 92cea8f..5edc800 100644 --- a/src/core.rs +++ b/src/core.rs @@ -94,22 +94,21 @@ impl Core { } }; - match self.flags.display { - Display::DirectoryItself => { - meta_list.push(meta); - } - _ => { - match meta.recurse_into(depth, &self.flags) { - Ok(content) => { - meta.content = content; - meta_list.push(meta); - } - Err(err) => { - print_error!("lsd: {}: {}\n", path.display(), err); - continue; - } - }; - } + let recurse = + self.flags.layout == Layout::Tree || self.flags.display != Display::DirectoryItself; + if recurse { + match meta.recurse_into(depth, &self.flags) { + Ok(content) => { + meta.content = content; + meta_list.push(meta); + } + Err(err) => { + print_error!("lsd: {}: {}\n", path.display(), err); + continue; + } + }; + } else { + meta_list.push(meta); }; } if self.flags.total_size.0 { diff --git a/src/flags/display.rs b/src/flags/display.rs index 574b94e..dd4ff05 100644 --- a/src/flags/display.rs +++ b/src/flags/display.rs @@ -15,7 +15,6 @@ pub enum Display { AlmostAll, DirectoryItself, DisplayOnlyVisible, - TreeD, } impl Display { @@ -46,11 +45,7 @@ impl Configurable for Display { } else if matches.is_present("almost-all") { Some(Self::AlmostAll) } else if matches.is_present("directory-only") { - if matches.is_present("tree") { - Some(Self::TreeD) - } else { - Some(Self::DirectoryItself) - } + Some(Self::DirectoryItself) } else { None } @@ -128,13 +123,6 @@ mod test { ); } - #[test] - fn test_from_arg_matches_display_only_directories() { - let argv = vec!["lsd", "--tree", "-d"]; - let matches = app::build().get_matches_from_safe(argv).unwrap(); - assert_eq!(Some(Display::TreeD), Display::from_arg_matches(&matches)); - } - #[test] fn test_from_config_none() { assert_eq!(None, Display::from_config(&Config::with_none())); diff --git a/src/meta/mod.rs b/src/meta/mod.rs index 8d82b6c..11ec321 100644 --- a/src/meta/mod.rs +++ b/src/meta/mod.rs @@ -54,7 +54,7 @@ impl Meta { return Ok(None); } - if flags.display == Display::DirectoryItself { + if flags.display == Display::DirectoryItself && flags.layout != Layout::Tree { return Ok(None); } @@ -118,9 +118,11 @@ impl Meta { }; // skip files for --tree -d - if let Display::TreeD = flags.display { - if !entry.file_type()?.is_dir() { - continue; + if flags.layout == Layout::Tree { + if let Display::DirectoryItself = flags.display { + if !entry.file_type()?.is_dir() { + continue; + } } }