Implement Pallet Remove #26

Merged
sfrembling merged 1 commits from working/#17 into main 2026-03-23 16:06:36 -06:00
Showing only changes of commit 290014f45d - Show all commits

View File

@@ -56,7 +56,7 @@ enum Subcommand {
}, },
/// List available build modes /// List available build modes
List, List,
/// Add a new package to the project (throguh pkg-config) /// Add a new package to the project (through pkg-config)
Add { Add {
/// The package to be added /// The package to be added
package: String, package: String,
@@ -69,6 +69,11 @@ enum Subcommand {
#[arg(long, short)] #[arg(long, short)]
args: Option<Vec<String>>, args: Option<Vec<String>>,
}, },
/// Removes a package from the project (through pkg-config)
Remove {
/// The package to remove
package: String,
},
} }
#[derive(clap::Subcommand)] #[derive(clap::Subcommand)]
@@ -201,9 +206,46 @@ impl App {
std::process::exit(1); 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<String>, args: Option<Vec<String>>) -> std::io::Result<()> { fn watch(mode: &Option<String>, args: Option<Vec<String>>) -> std::io::Result<()> {
use std::io::Write; use std::io::Write;