use std::{ env::current_dir, path::{Path, PathBuf}, }; use just_fmt::fmt_path::fmt_path; pub fn parse_path_input( files: Vec, recursive: bool, exclude_dir: Vec<&str>, ) -> Vec { let current_dir = current_dir().unwrap(); let files = if recursive { let mut result: Vec = Vec::new(); for arg in files.iter().skip(1) { if exclude_dir.contains(&arg.as_str()) { continue; } let path = current_dir.join(arg); if path.is_dir() { if let Err(e) = collect_files_recursively(&path, &mut result) { eprintln!("Error collecting files recursively: {}", e); continue; } } else { result.push(path); } } result } else { let mut result = Vec::new(); for arg in files.iter().skip(1) { if exclude_dir.contains(&arg.as_str()) { continue; } let path = current_dir.join(arg); if path.is_dir() { if files.len() == 2 { for entry in std::fs::read_dir(&path) .unwrap_or_else(|e| { eprintln!("Error reading directory: {}", e); std::fs::read_dir(".").unwrap() }) .flatten() { let entry_path = entry.path(); if !entry_path.is_dir() { result.push(entry_path); } } } } else { result.push(path); } } result }; files .into_iter() .filter_map(|path| match fmt_path(path) { Ok(formatted_path) => Some(formatted_path), Err(e) => { eprintln!("Error formatting path: {}", e); None } }) .collect() } fn collect_files_recursively(dir: &Path, files: &mut Vec) -> std::io::Result<()> { for entry in std::fs::read_dir(dir)? { let entry = entry?; let path = entry.path(); if path.is_dir() { collect_files_recursively(&path, files)?; } else { files.push(path); } } Ok(()) }