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