summaryrefslogtreecommitdiff
path: root/src/main.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/main.rs
parent371a77a994aeb0beae53f24a0edbf99d70133c33 (diff)
downloadrsrclean-main.tar
rsrclean-main.tar.gz
rsrclean-main.zip
add external cargoHEADmain
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs55
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 @@
1use std::path::{Path, PathBuf}; 1use std::path::PathBuf;
2 2
3use cargo::{
4 core::Workspace,
5 ops::{clean, CleanOptions},
6 util::{context::GlobalContext, interning::InternedString},
7 CargoResult,
8};
9use clap::Parser; 3use clap::Parser;
10 4
5use clean::handle_path;
11use cli::Args; 6use cli::Args;
12 7
8mod cargo;
9mod clean;
13mod cli; 10mod cli;
14 11
15fn main() { 12fn 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
25fn is_cargo_toml(path: &Path) -> bool {
26 path.is_file() && (path.file_name().unwrap() == "Cargo.toml")
27}
28
29fn 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
48fn 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}