From c619621cf3a38028d4c1db08dfcf4455ced566a5 Mon Sep 17 00:00:00 2001 From: godsfryingpan Date: Mon, 23 Mar 2026 16:06:36 -0600 Subject: [PATCH] Implement Pallet Remove (#26) closes #17 Reviewed-on: http://192.168.1.227:3000/sfrembling/pallet/pulls/26 Co-authored-by: godsfryingpan Co-committed-by: godsfryingpan --- src/app.rs | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 9664f27..d1a3f2f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -56,7 +56,7 @@ enum Subcommand { }, /// List available build modes List, - /// Add a new package to the project (throguh pkg-config) + /// Add a new package to the project (through pkg-config) Add { /// The package to be added package: String, @@ -69,6 +69,11 @@ enum Subcommand { #[arg(long, short)] args: Option>, }, + /// Removes a package from the project (through pkg-config) + Remove { + /// The package to remove + package: String, + }, } #[derive(clap::Subcommand)] @@ -201,10 +206,47 @@ impl App { std::process::exit(1); } } + Subcommand::Remove { package } => { + if let Err(e) = remove(&package) { + eprintln!("Error removing package {package} from project: {e}"); + std::process::exit(1); + } + } } } } +fn remove(package: &str) -> std::io::Result<()> { + let mut conf = get_config().ok_or(std::io::Error::new( + std::io::ErrorKind::NotFound, + "no Pallet.toml found in local directory", + ))?; + + let deps = conf.dependencies.get_or_insert_with(Vec::new); + + if let Some(index) = deps.iter().position(|dep| dep == package) { + deps.remove(index); + } else { + println!( + " {} package {package} not found in Pallet.toml, no change made", + "Warning".yellow().bold() + ); + return Ok(()); + } + + std::fs::write( + "Pallet.toml", + toml::to_string_pretty(&conf).expect("valid TOML"), + )?; + + println!( + " {} removed package {package}", + "Successfully".green().bold() + ); + + Ok(()) +} + fn watch(mode: &Option, args: Option>) -> std::io::Result<()> { use std::io::Write; use std::sync::Arc;