use crate::config::WjConfig;
use std::path::Path;
pub fn execute(package: &str) -> anyhow::Result<()> {
let wj_toml_path = Path::new("wj.toml");
if !wj_toml_path.exists() {
anyhow::bail!("wj.toml not found in current directory. Are you in a Windjammer project?");
}
let mut config =
WjConfig::load_from_file(wj_toml_path).map_err(|e| anyhow::anyhow!("{}", e))?;
let removed = config.remove_dependency(package);
if !removed {
anyhow::bail!("Dependency '{}' not found in wj.toml", package);
}
config
.save_to_file(wj_toml_path)
.map_err(|e| anyhow::anyhow!("{}", e))?;
let cargo_toml_content = config.to_cargo_toml();
std::fs::write("Cargo.toml", cargo_toml_content)?;
println!("✓ Removed {} from wj.toml", package);
println!("✓ Updated Cargo.toml");
if let Ok(output) = std::process::Command::new("cargo").arg("update").output() {
if output.status.success() {
println!("✓ Updated Cargo.lock");
}
}
Ok(())
}