Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,25 @@ fn set_working_dir(opts: &Opts) -> Result<()> {
fn ensure_search_pattern_is_not_a_path(opts: &Opts) -> Result<()> {
if !opts.full_path
&& opts.pattern.contains(std::path::MAIN_SEPARATOR)
&& Path::new(&opts.pattern).is_dir()
&& (!cfg!(windows) || Path::new(&opts.pattern).is_dir())
{
Err(anyhow!(
let pattern = &opts.pattern;
let sep = std::path::MAIN_SEPARATOR;
let mut message = format!(
"The search pattern '{pattern}' contains a path-separation character ('{sep}') \
and will not lead to any search results.\n\n\
If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n \
fd . '{pattern}'\n\n\
Instead, if you want your pattern to match the full file path, use:\n\n \
fd --full-path '{pattern}'",
pattern = &opts.pattern,
sep = std::path::MAIN_SEPARATOR,
))
and will not lead to any search results.\n"
);
if Path::new(pattern).is_dir() {
message += &format!(
"\nIf you want to search for all files inside the '{pattern}' directory, \
use a match-all pattern:\n\n fd . '{pattern}'\n"
);
}
message += &format!(
"\nIf you want your pattern to match the full file path, use:\n\n \
fd --full-path '{pattern}'"
);
Err(anyhow!(message))
} else {
Ok(())
}
Expand Down