Skip to content

Commit 1cdef5f

Browse files
AJ ONealmeain
authored andcommitted
use existing display and layout
1 parent 42c3c8c commit 1cdef5f

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Add support for `--extensionsort` `-X` from [aldhsu](https://github.com/aldhsu)
1212
- Add support for `--versionsort` `-v` from [zwpaper](https://github.com/zwpaper)
1313
- Add support for config symlink arrow from [zwpaper](https://github.com/zwpaper) [#409](https://github.com/Peltoche/lsd/issues/409)
14-
- Implement `--tree -d`, analogous to `tree -d` from [0jdxt](https://github.com/0jdxt)
14+
- Implement `--tree -d`, analogous to `tree -d` from [0jdxt](https://github.com/0jdxt) and [Utah Rust](https://github.com/utah-rust)
1515
### Changed
1616
- Use last sort flag for sort field from [meain](https://github.com/meain)
1717
### Fixed

src/core.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,21 @@ impl Core {
9494
}
9595
};
9696

97-
match self.flags.display {
98-
Display::DirectoryItself => {
99-
meta_list.push(meta);
100-
}
101-
_ => {
102-
match meta.recurse_into(depth, &self.flags) {
103-
Ok(content) => {
104-
meta.content = content;
105-
meta_list.push(meta);
106-
}
107-
Err(err) => {
108-
print_error!("lsd: {}: {}\n", path.display(), err);
109-
continue;
110-
}
111-
};
112-
}
97+
let recurse =
98+
self.flags.layout == Layout::Tree || self.flags.display != Display::DirectoryItself;
99+
if recurse {
100+
match meta.recurse_into(depth, &self.flags) {
101+
Ok(content) => {
102+
meta.content = content;
103+
meta_list.push(meta);
104+
}
105+
Err(err) => {
106+
print_error!("lsd: {}: {}\n", path.display(), err);
107+
continue;
108+
}
109+
};
110+
} else {
111+
meta_list.push(meta);
113112
};
114113
}
115114
if self.flags.total_size.0 {

src/flags/display.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub enum Display {
1515
AlmostAll,
1616
DirectoryItself,
1717
DisplayOnlyVisible,
18-
TreeD,
1918
}
2019

2120
impl Display {
@@ -46,11 +45,7 @@ impl Configurable<Self> for Display {
4645
} else if matches.is_present("almost-all") {
4746
Some(Self::AlmostAll)
4847
} else if matches.is_present("directory-only") {
49-
if matches.is_present("tree") {
50-
Some(Self::TreeD)
51-
} else {
52-
Some(Self::DirectoryItself)
53-
}
48+
Some(Self::DirectoryItself)
5449
} else {
5550
None
5651
}
@@ -128,13 +123,6 @@ mod test {
128123
);
129124
}
130125

131-
#[test]
132-
fn test_from_arg_matches_display_only_directories() {
133-
let argv = vec!["lsd", "--tree", "-d"];
134-
let matches = app::build().get_matches_from_safe(argv).unwrap();
135-
assert_eq!(Some(Display::TreeD), Display::from_arg_matches(&matches));
136-
}
137-
138126
#[test]
139127
fn test_from_config_none() {
140128
assert_eq!(None, Display::from_config(&Config::with_none()));

src/meta/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Meta {
5454
return Ok(None);
5555
}
5656

57-
if flags.display == Display::DirectoryItself {
57+
if flags.display == Display::DirectoryItself && flags.layout != Layout::Tree {
5858
return Ok(None);
5959
}
6060

@@ -118,9 +118,11 @@ impl Meta {
118118
};
119119

120120
// skip files for --tree -d
121-
if let Display::TreeD = flags.display {
122-
if !entry.file_type()?.is_dir() {
123-
continue;
121+
if flags.layout == Layout::Tree {
122+
if let Display::DirectoryItself = flags.display {
123+
if !entry.file_type()?.is_dir() {
124+
continue;
125+
}
124126
}
125127
}
126128

0 commit comments

Comments
 (0)