Skip to content
Myr

Add extension filtering

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Matthias Reitinger · committed by David Peter · parent 8073635 · Browse files · 3 files+41 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+41 added−4 removed

  • tests:+12 added−0 removed
  • other:+29 added−4 removed

3 files+41 added−4 removed

modified:src/main.rs+23 added
91 unmodified lines
92 ls_colors: Option<LsColors>,9394 /// The type of file to search for. All files other than the specified type will be ignored.95 file_type: FileType,9697 /// The extension to search for. Only entries matching the extension will be included.98 ///99 /// The value (if present) will be a lowercase string without leading dots.100 extension: Option<String>,101}102103/// The receiver thread can either be buffering results or directly streaming to the console.104enum ReceiverMode {
200 unmodified lines
305 return ignore::WalkState::Continue;306 },307 }308309 // Filter out unwanted extensions.310 match (&config.extension, entry.path().extension()) {311 (&None, _) => (),312 (&Some(_), None) => return ignore::WalkState::Continue,313 (&Some(ref e1), Some(e2)) => {314 if e1 != &e2.to_string_lossy().to_lowercase() {315 return ignore::WalkState::Continue;316 }317 },318 }319320 let path_rel_buf = match fshelper::path_relative_from(entry.path(), &*base) {321 Some(p) => p,322 None => error("Error: could not get relative path for directory entry.")323 };
96 unmodified lines
420 .long("type")421 .short("t")422 .takes_value(true)423 .possible_values(&["f", "file", "d", "directory", "s", "symlink"]))424 .arg(Arg::with_name("extension")425 .help("The file extension to search for")426 .long("extension")427 .short("e")428 .takes_value(true))429 .get_matches();430431 // Get the search pattern432 let empty_pattern = String::new();
75 unmodified lines
508 Some("d") | Some("directory") => FileType::Directory,509 Some("s") | Some("symlink") => FileType::SymLink,510 _ => FileType::Any,511 },512 extension: matches.value_of("extension")513 .map(|e| e.trim_left_matches('.').to_lowercase()),514 };515516 let root = Path::new(ROOT_DIR);517 let base = match config.path_display {
11 unmodified lines
modified:tests/test.sh+12 added
236 unmodified lines
237one/two/three238one/two/three/directory_foo" --type d239expect "symlink" --type s240241242suite "File extension (--ext)"243expect "a.foo244one/b.foo245one/two/c.foo246one/two/three/d.foo" --extension foo247expect "a.foo248one/b.foo249one/two/c.foo250one/two/three/d.foo" --extension .foo251expect "one/two/C.Foo2" --extension foo2252253# All done254echo
modified:README.md+6 added-4 removed