summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-08-14 22:42:03 +0200
committerfxqnlr <[email protected]>2024-08-14 22:42:03 +0200
commit0cf179e17ac60f72aba85e978379fb0957ae7aaa (patch)
treee262aba621908835e37ff0f82cdbad46a6f16c88 /src
downloadrsrclean-0cf179e17ac60f72aba85e978379fb0957ae7aaa.tar
rsrclean-0cf179e17ac60f72aba85e978379fb0957ae7aaa.tar.gz
rsrclean-0cf179e17ac60f72aba85e978379fb0957ae7aaa.zip
base working
Diffstat (limited to 'src')
-rw-r--r--src/main.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..cdc7d03
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,50 @@
1use std::path::Path;
2
3use cargo::{core::Workspace, ops::{clean, CleanOptions}, util::{context::GlobalContext, interning::InternedString}, CargoResult};
4
5fn main() {
6 let paths = std::fs::read_dir("./").unwrap();
7 for path in paths {
8 let p = path.unwrap();
9 handle_path(&p.path(), 0, 2);
10 }
11}
12
13fn is_cargo_toml(path: &Path) -> bool {
14 path.is_file() && (path.file_name().unwrap() == "Cargo.toml")
15}
16
17fn handle_path(path: &Path, iter: u8, max_iter: u8) {
18 if is_cargo_toml(path) {
19 let abs_path = std::fs::canonicalize(path).unwrap();
20 println!("Clean: {}", abs_path.as_path().to_str().unwrap());
21 clean_project(abs_path.as_path()).unwrap();
22 return;
23 };
24 if path.is_dir() {
25 if iter > max_iter { return; };
26 let paths = std::fs::read_dir(path).unwrap();
27 for path in paths {
28 let p = path.unwrap();
29 handle_path(&p.path(), iter + 1, 1);
30 };
31 }
32}
33
34fn clean_project(path: &Path) -> CargoResult<()> {
35 let gctx = GlobalContext::default()?;
36
37 let workspace = Workspace::new(path, &gctx)?;
38
39 let opts = CleanOptions {
40 gctx: &gctx,
41 spec: vec![],
42 targets: vec![],
43 profile_specified: false,
44 requested_profile: InternedString::new("dev"),
45 doc: false,
46 dry_run: true,
47 };
48
49 clean(&workspace, &opts)
50}