From 137346307248bc9e327847e549c3d6c24b3b11f3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sat, 17 Aug 2024 00:14:10 +0200 Subject: add external cargo --- src/clean.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/clean.rs (limited to 'src/clean.rs') diff --git a/src/clean.rs b/src/clean.rs new file mode 100644 index 0000000..a34a912 --- /dev/null +++ b/src/clean.rs @@ -0,0 +1,45 @@ +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); + } + } +} -- cgit v1.2.3