From 15f544e9763413eef63612ac455018c544301e88 Mon Sep 17 00:00:00 2001 From: timeshifter Date: Wed, 18 Jan 2023 14:25:08 +0100 Subject: [PATCH] add custom aur helper rm args --- src/backend/actual/pacman.rs | 8 ++++++++ src/config.rs | 2 ++ src/core.rs | 19 +++++++++--------- src/review.rs | 37 ++++++++++++++++++------------------ 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/backend/actual/pacman.rs b/src/backend/actual/pacman.rs index 4cfb217..36afe6d 100644 --- a/src/backend/actual/pacman.rs +++ b/src/backend/actual/pacman.rs @@ -10,6 +10,7 @@ use crate::{impl_backend_constants, Group, Package}; pub(crate) struct Pacman { pub(crate) binary: String, + pub(crate) aur_rm_args: Option>, pub(crate) packages: HashSet, } @@ -53,10 +54,16 @@ impl Backend for Pacman { /// Remove the specified packages. fn remove_packages(&self, packages: &[Package]) -> Result { let mut cmd = Command::new(&self.binary); + cmd.args(self.get_switches_remove()); + if let Some(rm_args) = &self.aur_rm_args { + cmd.args(rm_args); + } + for p in packages { cmd.arg(format!("{p}")); } + cmd.status() .with_context(|| format!("running command [{cmd:?}]")) } @@ -97,6 +104,7 @@ impl Pacman { pub(crate) fn new() -> Self { Self { binary: BINARY.to_string(), + aur_rm_args: None, packages: HashSet::new(), } } diff --git a/src/config.rs b/src/config.rs index 03a8fdc..01474a3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,6 +12,7 @@ const CONFIG_FILE_NAME: &str = "pacdef.yaml"; #[derive(Debug, Serialize, Deserialize)] pub struct Config { pub aur_helper: String, + pub aur_rm_args: Option>, pub warn_not_symlinks: bool, } @@ -55,6 +56,7 @@ impl Default for Config { fn default() -> Self { Self { aur_helper: "paru".into(), + aur_rm_args: None, warn_not_symlinks: true, } } diff --git a/src/core.rs b/src/core.rs index 360fa12..6471423 100644 --- a/src/core.rs +++ b/src/core.rs @@ -36,7 +36,7 @@ impl Pacdef { } #[allow(clippy::unit_arg)] - pub fn run_action_from_arg(self) -> Result<()> { + pub fn run_action_from_arg(mut self) -> Result<()> { match self.args.subcommand() { Some((CLEAN, _)) => self.clean_packages(), Some((EDIT, args)) => self.edit_group_files(args).context("editing group files"), @@ -60,11 +60,11 @@ impl Pacdef { } } - fn get_missing_packages(&self) -> ToDoPerBackend { + fn get_missing_packages(&mut self) -> ToDoPerBackend { let mut to_install = ToDoPerBackend::new(); for backend in Backends::iter() { - let mut backend = self.overwrite_binary_from_config(backend); + let mut backend = self.overwrite_values_from_config(backend); backend.load(&self.groups); @@ -77,10 +77,11 @@ impl Pacdef { to_install } - fn overwrite_binary_from_config(&self, backend: Box) -> Box { + fn overwrite_values_from_config(&mut self, backend: Box) -> Box { if backend.get_section() == "pacman" { Box::new(crate::backend::Pacman { binary: self.config.aur_helper.clone(), + aur_rm_args: self.config.aur_rm_args.take(), packages: HashSet::new(), }) } else { @@ -88,7 +89,7 @@ impl Pacdef { } } - fn install_packages(&self) -> Result<()> { + fn install_packages(&mut self) -> Result<()> { let to_install = self.get_missing_packages(); if to_install.nothing_to_do_for_all_backends() { @@ -138,17 +139,17 @@ impl Pacdef { println!("pacdef, version: {}", env!("CARGO_PKG_VERSION")); } - fn show_unmanaged_packages(self) { + fn show_unmanaged_packages(mut self) { let unmanaged_per_backend = &self.get_unmanaged_packages(); unmanaged_per_backend.show(None); } - fn get_unmanaged_packages(&self) -> ToDoPerBackend { + fn get_unmanaged_packages(&mut self) -> ToDoPerBackend { let mut result = ToDoPerBackend::new(); for backend in Backends::iter() { - let mut backend = self.overwrite_binary_from_config(backend); + let mut backend = self.overwrite_values_from_config(backend); backend.load(&self.groups); @@ -168,7 +169,7 @@ impl Pacdef { } } - fn clean_packages(self) -> Result<()> { + fn clean_packages(mut self) -> Result<()> { let to_remove = self.get_unmanaged_packages(); if to_remove.is_empty() { diff --git a/src/review.rs b/src/review.rs index b490a9b..d94274d 100644 --- a/src/review.rs +++ b/src/review.rs @@ -60,24 +60,25 @@ fn get_action_for_package( reviews: &mut Reviews, backend: &Rc>, ) -> Result<()> { - loop { - match ask_user_action_for_package()? { - ReviewAction::AsDependency => todo!(), - ReviewAction::AssignGroupBackend => { - if let Some(val) = assign_group_backend(&package, groups)? { - break; - }; - } - ReviewAction::Delete => { - reviews.delete.push((backend.clone(), package)); - break; - } - ReviewAction::Info => backend.show_package_info(&package)?, - ReviewAction::Invalid => (), - ReviewAction::Skip => break, - ReviewAction::Quit => bail!("user wants to quit"), - } - } + todo!(); + // loop { + // match ask_user_action_for_package()? { + // ReviewAction::AsDependency => todo!(), + // ReviewAction::AssignGroupBackend => { + // if let Some(val) = assign_group_backend(&package, groups)? { + // break; + // }; + // } + // ReviewAction::Delete => { + // reviews.delete.push((backend.clone(), package)); + // break; + // } + // ReviewAction::Info => backend.show_package_info(&package)?, + // ReviewAction::Invalid => (), + // ReviewAction::Skip => break, + // ReviewAction::Quit => bail!("user wants to quit"), + // } + // } Ok(()) }