Skip to content
Myr

Error if user supplied path instead of pattern

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

authored by sharkdp · committed by David Peter · parent 89a8f55 · Browse files · 1 file+16 added−0 removed
This commit

State

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

Diff stats

1 file+16 added−0 removed

  • other:+16 added−0 removed

1 file+16 added−0 removed

modified:src/main.rs+16 added
75 unmodified lines
76 .map(|path_buffer| fshelper::absolute_path(path_buffer).unwrap())77 .collect();78 }7980 // Detect if the user accidentally supplied a path instead of a search pattern81 if !matches.is_present("full-path") && pattern.contains(std::path::MAIN_SEPARATOR)82 && fshelper::is_dir(Path::new(pattern))83 {84 error(&format!(85 "Error: The search pattern '{pattern}' contains a path-separation character ('{sep}') \86 and will not lead to any search results.\n\n\87 If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n \88 fd . '{pattern}'\n\n\89 Instead, if you want to search for the pattern in the full path, use:\n\n \90 fd --full-path '{pattern}'",91 pattern = pattern,92 sep = std::path::MAIN_SEPARATOR,93 ));94 }9596 // Treat pattern as literal string if '--fixed-strings' is used97 let pattern_regex = if matches.is_present("fixed-strings") {98 regex::escape(pattern)99 } else {
102 unmodified lines