From 137346307248bc9e327847e549c3d6c24b3b11f3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sat, 17 Aug 2024 00:14:10 +0200 Subject: add external cargo --- src/main.rs | 55 +++++-------------------------------------------------- 1 file changed, 5 insertions(+), 50 deletions(-) (limited to 'src/main.rs') 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 @@ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; -use cargo::{ - core::Workspace, - ops::{clean, CleanOptions}, - util::{context::GlobalContext, interning::InternedString}, - CargoResult, -}; use clap::Parser; +use clean::handle_path; use cli::Args; +mod cargo; +mod clean; mod cli; fn main() { @@ -18,48 +15,6 @@ fn main() { let paths = std::fs::read_dir(cli.clone().dir.unwrap_or(PathBuf::from("./"))).unwrap(); for path in paths { let p = path.unwrap(); - handle_path(&p.path(), 0, cli.clone()); + handle_path(&p.path(), 0, &cli); } } - -fn is_cargo_toml(path: &Path) -> bool { - path.is_file() && (path.file_name().unwrap() == "Cargo.toml") -} - -fn handle_path(path: &Path, iter: u8, cli: Args) { - if is_cargo_toml(path) { - let abs_path = std::fs::canonicalize(path).unwrap(); - println!("Clean: {}", abs_path.as_path().to_str().unwrap()); - clean_project(abs_path.as_path(), cli).unwrap(); - return; - }; - if path.is_dir() { - if iter >= cli.level { - return; - }; - let paths = std::fs::read_dir(path).unwrap(); - for path in paths { - let p = path.unwrap(); - handle_path(&p.path(), iter + 1, cli.clone()); - } - } -} - -fn clean_project(path: &Path, cli: Args) -> CargoResult<()> { - let gctx = GlobalContext::default()?; - - let workspace = Workspace::new(path, &gctx)?; - - let opts = CleanOptions { - gctx: &gctx, - spec: vec![], - targets: vec![], - profile_specified: false, - requested_profile: InternedString::new("dev"), - doc: cli.doc, - dry_run: cli.dry_run, - }; - - // return Ok(()); - clean(&workspace, &opts) -} -- cgit v1.2.3