use crate::common::{SummaryItem, print_summary, search_unique_package, yesno}; use anyhow::anyhow; use clap::Parser; use packie::{PackieBuilder, package::PkgSpec}; use rust_i18n::t; #[derive(Debug, Parser)] pub struct Cli { #[arg(short, long)] yes: bool, items: Vec, } pub fn main(cli: Cli) -> Result<(), crate::Error> { let mut packie = PackieBuilder::new().build()?; let mut packages = Vec::with_capacity(cli.items.len()); for pkgspec in cli.items { packages.push(search_unique_package(&mut packie, &pkgspec)?); } let summary = packages .iter() .map(|x| SummaryItem { pkgspec: x.install_pkgspec.clone(), pkgident: x.pkg_manifest.pkg_ident(), operation: SummaryItem::REMOVE, }) .collect(); println!("{}", t!("remove.prompt_to_remove")); println!(); print_summary(summary); println!(); if cli.yes { println!("y"); } else if !yesno(&t!("remove.confirm_removal"), false) { println!("{}", t!("remove.aborting")); return Ok(()); } for i in packages { println!( "{}", t!("remove.action_hint", package = i.pkg_manifest.pkg_ident()) ); packie .remove(&i.pkg_manifest.pkg_ident().into()) .map_err(|error| anyhow!("{}", t!("remove.action_failure", error = error)))?; } Ok(()) }