diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 50 |
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 @@ | |||
1 | use std::path::Path; | ||
2 | |||
3 | use cargo::{core::Workspace, ops::{clean, CleanOptions}, util::{context::GlobalContext, interning::InternedString}, CargoResult}; | ||
4 | |||
5 | fn 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 | |||
13 | fn is_cargo_toml(path: &Path) -> bool { | ||
14 | path.is_file() && (path.file_name().unwrap() == "Cargo.toml") | ||
15 | } | ||
16 | |||
17 | fn 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 | |||
34 | fn 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 | } | ||