diff --git a/crates/pacdef_core/src/backend/actual/flatpak.rs b/crates/pacdef_core/src/backend/actual/flatpak.rs index 8d23d64..47bcf9e 100644 --- a/crates/pacdef_core/src/backend/actual/flatpak.rs +++ b/crates/pacdef_core/src/backend/actual/flatpak.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use std::process::Command; use std::process::ExitStatus; -use anyhow::Result; +use anyhow::{Context, Result}; use crate::backend::backend_trait::{Backend, Switches, Text}; use crate::{impl_backend_constants, Group, Package}; @@ -27,14 +27,6 @@ const SUPPORTS_AS_DEPENDENCY: bool = false; impl Backend for Flatpak { impl_backend_constants!(); - fn get_switches_runtime(&self) -> Switches { - if self.systemwide { - &[] - } else { - &["--user"] - } - } - fn get_all_installed_packages(&self) -> Result> { self.get_installed_packages(true) } @@ -43,9 +35,55 @@ impl Backend for Flatpak { self.get_installed_packages(false) } + /// Install the specified packages. + fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result { + let mut cmd = Command::new(self.get_binary()); + cmd.args(self.get_switches_install()); + cmd.args(self.get_switches_runtime()); + + if noconfirm { + cmd.args(self.get_switches_noconfirm()); + } + + for p in packages { + cmd.arg(format!("{p}")); + } + + cmd.status() + .with_context(|| format!("running command {cmd:?}")) + } + fn make_dependency(&self, _: &[Package]) -> Result { panic!("not supported by {}", BINARY) } + + /// Remove the specified packages. + fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result { + let mut cmd = Command::new(self.get_binary()); + cmd.args(self.get_switches_remove()); + cmd.args(self.get_switches_runtime()); + + if noconfirm { + cmd.args(self.get_switches_noconfirm()); + } + + for p in packages { + cmd.arg(format!("{p}")); + } + + cmd.status() + .with_context(|| format!("running command [{cmd:?}]")) + } + + /// Show information from package manager for package. + fn show_package_info(&self, package: &Package) -> Result { + let mut cmd = Command::new(self.get_binary()); + cmd.args(self.get_switches_info()); + cmd.args(self.get_switches_runtime()); + cmd.arg(format!("{package}")); + cmd.status() + .with_context(|| format!("running command {cmd:?}")) + } } impl Flatpak { @@ -56,6 +94,14 @@ impl Flatpak { } } + fn get_switches_runtime(&self) -> Switches { + if self.systemwide { + &[] + } else { + &["--user"] + } + } + fn get_installed_packages(&self, include_implicit: bool) -> Result> { let mut cmd = Command::new(BINARY); cmd.args(["list", "--columns=application"]); diff --git a/crates/pacdef_core/src/backend/backend_trait.rs b/crates/pacdef_core/src/backend/backend_trait.rs index 4b7c481..98cfddb 100644 --- a/crates/pacdef_core/src/backend/backend_trait.rs +++ b/crates/pacdef_core/src/backend/backend_trait.rs @@ -49,11 +49,6 @@ pub trait Backend: Debug { /// [`Backend::supports_as_dependency`]. fn get_switches_make_dependency(&self) -> Switches; - /// Get CLI switches evaluated at runtime - fn get_switches_runtime(&self) -> Switches { - &[] - } - /// Load all packages from a set of groups. The backend will visit all groups, /// find its own section, and clone all packages into its own struct. fn load(&mut self, groups: &HashSet); @@ -85,7 +80,6 @@ pub trait Backend: Debug { fn install_packages(&self, packages: &[Package], noconfirm: bool) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_install()); - cmd.args(self.get_switches_runtime()); if noconfirm { cmd.args(self.get_switches_noconfirm()); @@ -108,7 +102,6 @@ pub trait Backend: Debug { fn make_dependency(&self, packages: &[Package]) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_make_dependency()); - cmd.args(self.get_switches_runtime()); for p in packages { cmd.arg(format!("{p}")); @@ -122,7 +115,6 @@ pub trait Backend: Debug { fn remove_packages(&self, packages: &[Package], noconfirm: bool) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_remove()); - cmd.args(self.get_switches_runtime()); if noconfirm { cmd.args(self.get_switches_noconfirm()); @@ -151,7 +143,6 @@ pub trait Backend: Debug { fn show_package_info(&self, package: &Package) -> Result { let mut cmd = Command::new(self.get_binary()); cmd.args(self.get_switches_info()); - cmd.args(self.get_switches_runtime()); cmd.arg(format!("{package}")); cmd.status() .with_context(|| format!("running command {cmd:?}"))