add custom aur helper rm args

This commit is contained in:
timeshifter
2023-01-18 14:25:08 +01:00
parent df60662d40
commit 15f544e976
4 changed files with 39 additions and 27 deletions
+8
View File
@@ -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<Vec<String>>,
pub(crate) packages: HashSet<Package>,
}
@@ -53,10 +54,16 @@ impl Backend for Pacman {
/// Remove the specified packages.
fn remove_packages(&self, packages: &[Package]) -> Result<ExitStatus> {
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(),
}
}
+2
View File
@@ -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<Vec<String>>,
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,
}
}
+10 -9
View File
@@ -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<dyn Backend>) -> Box<dyn Backend> {
fn overwrite_values_from_config(&mut self, backend: Box<dyn Backend>) -> Box<dyn Backend> {
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() {
+19 -18
View File
@@ -60,24 +60,25 @@ fn get_action_for_package(
reviews: &mut Reviews,
backend: &Rc<Box<dyn Backend>>,
) -> 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(())
}