use std::path::{Path, PathBuf};
#[must_use]
pub fn collect_watch_dirs(inputs: &[String]) -> Vec<PathBuf> {
let mut dirs: Vec<PathBuf> = Vec::new();
let mut seen: std::collections::HashSet<PathBuf> = std::collections::HashSet::new();
for input_str in inputs {
let is_glob = input_str.contains('*') || input_str.contains('?') || input_str.contains('[');
if is_glob {
if let Some(ancestor) = Path::new(input_str).ancestors().find(|p| p.exists()) {
let dir = ancestor
.canonicalize()
.unwrap_or_else(|_| ancestor.to_path_buf());
if seen.insert(dir.clone()) {
dirs.push(dir);
}
}
} else {
let path = Path::new(input_str);
if path.is_file() {
if let Some(parent) = path.parent() {
let dir = parent
.canonicalize()
.unwrap_or_else(|_| parent.to_path_buf());
if seen.insert(dir.clone()) {
dirs.push(dir);
}
}
} else if path.is_dir() {
let dir = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
if seen.insert(dir.clone()) {
dirs.push(dir);
}
}
}
}
dirs
}
pub(super) fn format_paths_display(dirs: &[PathBuf]) -> String {
if dirs.len() > 3 {
format!("{} directories", dirs.len())
} else {
dirs.iter()
.map(|d| d.display().to_string())
.collect::<Vec<_>>()
.join(", ")
}
}