use std::path::{Path, PathBuf};
use ignore::WalkBuilder;
pub fn collect(paths: &[PathBuf]) -> Result<Vec<PathBuf>, String> {
let mut files = Vec::new();
for path in paths {
if path.is_file() {
files.push(path.clone());
} else if path.is_dir() {
for entry in WalkBuilder::new(path).require_git(false).build() {
let entry = entry.map_err(|e| e.to_string())?;
let is_blade = entry.file_name().to_string_lossy().ends_with(".blade.php");
if is_blade && entry.file_type().is_some_and(|t| t.is_file()) {
files.push(entry.into_path());
}
}
} else {
return Err(format!("{}: no such file or directory", display(path)));
}
}
files.sort();
files.dedup();
Ok(files)
}
pub fn display(path: &Path) -> String {
let shown = path.to_string_lossy().replace('\\', "/");
match shown.strip_prefix("./") {
Some(rest) => rest.to_string(),
None => shown,
}
}