mirror of
https://github.com/lsd-rs/lsd
synced 2025-01-06 08:58:44 +00:00
Implement lsd --tree -d
This commit implements the `-d` option in combination with `--tree` to mimic `tree -d` behaviour. There are also changes to the behaviour of `--tree` and `-R` such that they follow the same behaviour as `tree -d` and `ls -R` i.e. not follwoing symlinked directories unless the `-L` flag is specified.
This commit is contained in:
parent
b6bd1d3b55
commit
c67c639327
5 changed files with 30 additions and 2 deletions
|
@ -11,6 +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 `--extensionsort` `-X` from [aldhsu](https://github.com/aldhsu)
|
||||||
- Add support for `--versionsort` `-v` from [zwpaper](https://github.com/zwpaper)
|
- 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)
|
- 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)
|
||||||
### Changed
|
### Changed
|
||||||
- Use last sort flag for sort field from [meain](https://github.com/meain)
|
- Use last sort flag for sort field from [meain](https://github.com/meain)
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -116,7 +116,6 @@ pub fn build() -> App<'static, 'static> {
|
||||||
.conflicts_with("almost-all")
|
.conflicts_with("almost-all")
|
||||||
.conflicts_with("depth")
|
.conflicts_with("depth")
|
||||||
.conflicts_with("recursive")
|
.conflicts_with("recursive")
|
||||||
.conflicts_with("tree")
|
|
||||||
.help("Display directories themselves, and not their contents"),
|
.help("Display directories themselves, and not their contents"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
|
|
@ -15,6 +15,7 @@ pub enum Display {
|
||||||
AlmostAll,
|
AlmostAll,
|
||||||
DirectoryItself,
|
DirectoryItself,
|
||||||
DisplayOnlyVisible,
|
DisplayOnlyVisible,
|
||||||
|
TreeD,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display {
|
impl Display {
|
||||||
|
@ -45,7 +46,11 @@ impl Configurable<Self> for Display {
|
||||||
} else if matches.is_present("almost-all") {
|
} else if matches.is_present("almost-all") {
|
||||||
Some(Self::AlmostAll)
|
Some(Self::AlmostAll)
|
||||||
} else if matches.is_present("directory-only") {
|
} else if matches.is_present("directory-only") {
|
||||||
Some(Self::DirectoryItself)
|
if matches.is_present("tree") {
|
||||||
|
Some(Self::TreeD)
|
||||||
|
} else {
|
||||||
|
Some(Self::DirectoryItself)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,11 @@ impl Meta {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// skip files for --tree -d
|
||||||
|
if flags.display == Display::TreeD && !entry_meta.file_type.is_dirlike() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
match entry_meta.recurse_into(depth - 1, &flags) {
|
match entry_meta.recurse_into(depth - 1, &flags) {
|
||||||
Ok(content) => entry_meta.content = content,
|
Ok(content) => entry_meta.content = content,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
@ -397,6 +397,24 @@ fn test_bad_utf_8_name() {
|
||||||
.stdout(predicate::str::is_match("bad-name\u{fffd}\u{fffd}.ext\n$").unwrap());
|
.stdout(predicate::str::is_match("bad-name\u{fffd}\u{fffd}.ext\n$").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tree_d() {
|
||||||
|
let tmp = tempdir();
|
||||||
|
tmp.child("one").touch().unwrap();
|
||||||
|
tmp.child("two").touch().unwrap();
|
||||||
|
tmp.child("one.d").create_dir_all().unwrap();
|
||||||
|
tmp.child("one.d/one").touch().unwrap();
|
||||||
|
tmp.child("one.d/one.d").create_dir_all().unwrap();
|
||||||
|
tmp.child("two.d").create_dir_all().unwrap();
|
||||||
|
|
||||||
|
cmd()
|
||||||
|
.arg(tmp.path())
|
||||||
|
.arg("--tree")
|
||||||
|
.arg("-d")
|
||||||
|
.assert()
|
||||||
|
.stdout(predicate::str::is_match("├── one.d\n│ └── one.d\n└── two.d\n$").unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
fn cmd() -> Command {
|
fn cmd() -> Command {
|
||||||
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue