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/cargo/external.rs | 19 +++++++++++++++++++ src/cargo/internal.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/cargo/external.rs create mode 100644 src/cargo/internal.rs (limited to 'src/cargo') diff --git a/src/cargo/external.rs b/src/cargo/external.rs new file mode 100644 index 0000000..c956b68 --- /dev/null +++ b/src/cargo/external.rs @@ -0,0 +1,19 @@ +use std::{path::Path, process::Command}; + +use crate::cli::Args; + +pub fn clean_ext(path: &Path, cli: &Args) { + let mut args = vec!["clean", "--manifest-path", path.to_str().unwrap()]; + if cli.dry_run { + args.push("--dry-run"); + } + if cli.doc { + args.push("--doc"); + } + Command::new("cargo") + .args(args) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); +} diff --git a/src/cargo/internal.rs b/src/cargo/internal.rs new file mode 100644 index 0000000..b3e44e4 --- /dev/null +++ b/src/cargo/internal.rs @@ -0,0 +1,28 @@ +use std::path::Path; + +use cargo::{ + core::Workspace, + ops::{clean, CleanOptions}, + util::{context::GlobalContext, interning::InternedString}, + CargoResult, +}; + +use crate::cli::Args; + +pub fn clean_int(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, + }; + + clean(&workspace, &opts) +} -- cgit v1.2.3