use std::path::Path; use crate::cli::Args; fn is_cargo_toml(path: &Path) -> bool { path.is_file() && (path.file_name().unwrap() == "Cargo.toml") } pub fn handle_path(path: &Path, iter: u8, cli: &Args) { if is_cargo_toml(path) { let abs_path = std::fs::canonicalize(path).unwrap(); println!("Clean: {}", abs_path.as_path().to_str().unwrap()); #[cfg(all(feature = "int-cargo", feature = "ext-cargo"))] { if cli.ext_cargo { crate::cargo::clean_ext(abs_path.as_path(), cli); } else { crate::cargo::clean_int(abs_path.as_path(), cli).unwrap(); }; } #[cfg(all(feature = "int-cargo", not(feature = "ext-cargo")))] { crate::cargo::clean_int(abs_path.as_path(), cli).unwrap(); } #[cfg(all(feature = "ext-cargo", not(feature = "int-cargo")))] { crate::cargo::clean_ext(abs_path.as_path(), cli); } return; }; if path.is_dir() { if iter >= cli.level { return; }; let paths = std::fs::read_dir(path).unwrap(); for path in paths { let p = path.unwrap(); handle_path(&p.path(), iter + 1, cli); } } }