summaryrefslogtreecommitdiff
path: root/src/clean.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-08-17 00:14:10 +0200
committerfxqnlr <[email protected]>2024-08-17 00:14:10 +0200
commit137346307248bc9e327847e549c3d6c24b3b11f3 (patch)
tree94d73000aa881c912f93eccbfb9e0d0a7c5857ea /src/clean.rs
parent371a77a994aeb0beae53f24a0edbf99d70133c33 (diff)
downloadrsrclean-main.tar
rsrclean-main.tar.gz
rsrclean-main.zip
add external cargoHEADmain
Diffstat (limited to 'src/clean.rs')
-rw-r--r--src/clean.rs45
1 files changed, 45 insertions, 0 deletions
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 @@
1use std::path::Path;
2
3use crate::cli::Args;
4
5fn is_cargo_toml(path: &Path) -> bool {
6 path.is_file() && (path.file_name().unwrap() == "Cargo.toml")
7}
8
9pub fn handle_path(path: &Path, iter: u8, cli: &Args) {
10 if is_cargo_toml(path) {
11 let abs_path = std::fs::canonicalize(path).unwrap();
12 println!("Clean: {}", abs_path.as_path().to_str().unwrap());
13
14 #[cfg(all(feature = "int-cargo", feature = "ext-cargo"))]
15 {
16 if cli.ext_cargo {
17 crate::cargo::clean_ext(abs_path.as_path(), cli);
18 } else {
19 crate::cargo::clean_int(abs_path.as_path(), cli).unwrap();
20 };
21 }
22
23 #[cfg(all(feature = "int-cargo", not(feature = "ext-cargo")))]
24 {
25 crate::cargo::clean_int(abs_path.as_path(), cli).unwrap();
26 }
27
28 #[cfg(all(feature = "ext-cargo", not(feature = "int-cargo")))]
29 {
30 crate::cargo::clean_ext(abs_path.as_path(), cli);
31 }
32
33 return;
34 };
35 if path.is_dir() {
36 if iter >= cli.level {
37 return;
38 };
39 let paths = std::fs::read_dir(path).unwrap();
40 for path in paths {
41 let p = path.unwrap();
42 handle_path(&p.path(), iter + 1, cli);
43 }
44 }
45}