diff options
author | fxqnlr <[email protected]> | 2024-08-17 00:14:10 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-08-17 00:14:10 +0200 |
commit | 137346307248bc9e327847e549c3d6c24b3b11f3 (patch) | |
tree | 94d73000aa881c912f93eccbfb9e0d0a7c5857ea /src/main.rs | |
parent | 371a77a994aeb0beae53f24a0edbf99d70133c33 (diff) | |
download | rsrclean-137346307248bc9e327847e549c3d6c24b3b11f3.tar rsrclean-137346307248bc9e327847e549c3d6c24b3b11f3.tar.gz rsrclean-137346307248bc9e327847e549c3d6c24b3b11f3.zip |
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 55 |
1 files changed, 5 insertions, 50 deletions
diff --git a/src/main.rs b/src/main.rs index beac641..6bcf5b5 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,15 +1,12 @@ | |||
1 | use std::path::{Path, PathBuf}; | 1 | use std::path::PathBuf; |
2 | 2 | ||
3 | use cargo::{ | ||
4 | core::Workspace, | ||
5 | ops::{clean, CleanOptions}, | ||
6 | util::{context::GlobalContext, interning::InternedString}, | ||
7 | CargoResult, | ||
8 | }; | ||
9 | use clap::Parser; | 3 | use clap::Parser; |
10 | 4 | ||
5 | use clean::handle_path; | ||
11 | use cli::Args; | 6 | use cli::Args; |
12 | 7 | ||
8 | mod cargo; | ||
9 | mod clean; | ||
13 | mod cli; | 10 | mod cli; |
14 | 11 | ||
15 | fn main() { | 12 | fn main() { |
@@ -18,48 +15,6 @@ fn main() { | |||
18 | let paths = std::fs::read_dir(cli.clone().dir.unwrap_or(PathBuf::from("./"))).unwrap(); | 15 | let paths = std::fs::read_dir(cli.clone().dir.unwrap_or(PathBuf::from("./"))).unwrap(); |
19 | for path in paths { | 16 | for path in paths { |
20 | let p = path.unwrap(); | 17 | let p = path.unwrap(); |
21 | handle_path(&p.path(), 0, cli.clone()); | 18 | handle_path(&p.path(), 0, &cli); |
22 | } | 19 | } |
23 | } | 20 | } |
24 | |||
25 | fn is_cargo_toml(path: &Path) -> bool { | ||
26 | path.is_file() && (path.file_name().unwrap() == "Cargo.toml") | ||
27 | } | ||
28 | |||
29 | fn handle_path(path: &Path, iter: u8, cli: Args) { | ||
30 | if is_cargo_toml(path) { | ||
31 | let abs_path = std::fs::canonicalize(path).unwrap(); | ||
32 | println!("Clean: {}", abs_path.as_path().to_str().unwrap()); | ||
33 | clean_project(abs_path.as_path(), cli).unwrap(); | ||
34 | return; | ||
35 | }; | ||
36 | if path.is_dir() { | ||
37 | if iter >= cli.level { | ||
38 | return; | ||
39 | }; | ||
40 | let paths = std::fs::read_dir(path).unwrap(); | ||
41 | for path in paths { | ||
42 | let p = path.unwrap(); | ||
43 | handle_path(&p.path(), iter + 1, cli.clone()); | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | |||
48 | fn clean_project(path: &Path, cli: Args) -> CargoResult<()> { | ||
49 | let gctx = GlobalContext::default()?; | ||
50 | |||
51 | let workspace = Workspace::new(path, &gctx)?; | ||
52 | |||
53 | let opts = CleanOptions { | ||
54 | gctx: &gctx, | ||
55 | spec: vec![], | ||
56 | targets: vec![], | ||
57 | profile_specified: false, | ||
58 | requested_profile: InternedString::new("dev"), | ||
59 | doc: cli.doc, | ||
60 | dry_run: cli.dry_run, | ||
61 | }; | ||
62 | |||
63 | // return Ok(()); | ||
64 | clean(&workspace, &opts) | ||
65 | } | ||