Browse Source

Add --prune flag

closes #535
pull/677/head
Matthias Reitinger 6 months ago
committed by GitHub
parent
commit
ec4cc981fc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 0 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +3
    -0
      contrib/completion/_fd
  3. +3
    -0
      doc/fd.1
  4. +7
    -0
      src/app.rs
  5. +1
    -0
      src/main.rs
  6. +3
    -0
      src/options.rs
  7. +5
    -0
      src/walk.rs
  8. +34
    -0
      tests/tests.rs

+ 1
- 0
CHANGELOG.md View File

@ -3,6 +3,7 @@
## Features
- Improved the usability of the time-based options, see #624 and #645 (@gorogoroumaru)
- Add new `--prune` flag, see #535 (@reima)
## Bugfixes


+ 3
- 0
contrib/completion/_fd View File

@ -102,6 +102,9 @@ _fd() {
'(--exact-depth --min-depth)--min-depth=[set directory depth to descend before start searching]:depth'
'(--exact-depth -d --max-depth --maxdepth --min-depth)--exact-depth=[only search at the exact given directory depth]:depth'
+ prune # pruning
"--prune[don't traverse into matching directories]"
+ filter-misc # filter search
'*'{-t+,--type=}"[filter search by type]:type:(($fd_types))"
'*'{-e+,--extension=}'[filter search by file extension]:extension'


+ 3
- 0
doc/fd.1 View File

@ -115,6 +115,9 @@ Only show search results starting at the given depth. See also: '--max-depth' an
.BI "\-\-exact\-depth " d
Only show search results at the exact given depth. This is an alias for '--min-depth <depth> --max-depth <depth>'.
.TP
.B \-\-prune
Do not traverse into matching directories.
.TP
.BI "\-t, \-\-type " filetype
Filter search by type:
.RS


+ 7
- 0
src/app.rs View File

@ -215,6 +215,13 @@ pub fn build_app() -> App<'static, 'static> {
'--min-depth <depth> --max-depth <depth>'.",
),
)
.arg(
Arg::with_name("prune")
.long("prune")
.conflicts_with_all(&["size", "exact-depth"])
.hidden_short_help(true)
.long_help("Do not traverse into matching directories.")
)
.arg(
Arg::with_name("file-type")
.long("type")


+ 1
- 0
src/main.rs View File

@ -323,6 +323,7 @@ fn run() -> Result<ExitCode> {
.value_of("min-depth")
.or_else(|| matches.value_of("exact-depth"))
.and_then(|n| usize::from_str_radix(n, 10).ok()),
prune: matches.is_present("prune"),
threads: std::cmp::max(
matches
.value_of("threads")


+ 3
- 0
src/options.rs View File

@ -48,6 +48,9 @@ pub struct Options {
/// The minimum depth for reported entries, or `None`.
pub min_depth: Option<usize>,
/// Whether to stop traversing into matching directories.
pub prune: bool,
/// The number of threads to use.
pub threads: usize,


+ 5
- 0
src/walk.rs View File

@ -494,6 +494,11 @@ fn spawn_senders(
return ignore::WalkState::Quit;
}
// Apply pruning.
if config.prune {
return ignore::WalkState::Skip;
}
ignore::WalkState::Continue
})
});


+ 34
- 0
tests/tests.rs View File

@ -758,6 +758,40 @@ fn test_exact_depth() {
);
}
/// Pruning (--prune)
#[test]
fn test_prune() {
let dirs = &["foo/bar", "bar/foo", "baz"];
let files = &[
"foo/foo.file",
"foo/bar/foo.file",
"bar/foo.file",
"bar/foo/foo.file",
"baz/foo.file",
];
let te = TestEnv::new(dirs, files);
te.assert_output(
&["foo"],
"foo
foo/foo.file
foo/bar/foo.file
bar/foo.file
bar/foo
bar/foo/foo.file
baz/foo.file",
);
te.assert_output(
&["--prune", "foo"],
"foo
bar/foo
bar/foo.file
baz/foo.file",
);
}
/// Absolute paths (--absolute-path)
#[test]
fn test_absolute_path() {


Loading…
Cancel
Save