make arch an optional backend

This commit is contained in:
steven-omaha
2023-02-27 16:12:46 +01:00
parent 1cd6357560
commit 0affcff900
4 changed files with 13 additions and 3 deletions
+5 -1
View File
@@ -13,7 +13,7 @@ categories = ["command-line-utilities"]
features = ["alpm/docs-rs"]
[dependencies]
alpm = "2.2"
alpm = { version = "2.2", optional = true }
anyhow = { workspace = true }
clap = "4.1"
const_format = { version = "0.2", default-features = false }
@@ -27,3 +27,7 @@ serde_derive = "1.0"
serde = "1.0"
pacdef_macros = { path = "../pacdef_macros", version = "0.1" }
[features]
default = ["arch"]
arch = ["dep:alpm"]
@@ -1,2 +1,3 @@
#[cfg(feature = "arch")]
pub mod arch;
pub mod rust;
+1
View File
@@ -12,6 +12,7 @@ use pacdef_macros::Register;
#[derive(Debug, Register)]
pub enum Backends {
#[cfg(feature = "arch")]
Arch,
Rust,
}
+6 -2
View File
@@ -9,7 +9,7 @@ use const_format::formatcp;
use crate::action::*;
use crate::args;
use crate::backend::{Arch, Backend, Backends, ToDoPerBackend};
use crate::backend::{Backend, Backends, ToDoPerBackend};
use crate::cmd::run_edit_command;
use crate::env::get_single_var;
use crate::path::get_group_dir;
@@ -23,6 +23,7 @@ const UNREACHABLE_ARM: &str = "argument parser requires some subcommand to retur
const ACTION_NOT_MATCHED: &str = "could not match action";
/// Most data that is required during runtime of the program.
#[allow(dead_code)] // "`config` is only needed on Arch Linux"
pub struct Pacdef {
args: ArgMatches,
config: Config,
@@ -94,6 +95,7 @@ impl Pacdef {
let mut to_install = ToDoPerBackend::new();
for mut backend in Backends::iter() {
#[cfg(feature = "arch")]
self.overwrite_values_from_config(&mut *backend);
backend.load(&self.groups);
@@ -107,8 +109,9 @@ impl Pacdef {
to_install
}
#[cfg(feature = "arch")]
fn overwrite_values_from_config(&mut self, backend: &mut dyn Backend) {
if let Some(arch) = backend.as_any_mut().downcast_mut::<Arch>() {
if let Some(arch) = backend.as_any_mut().downcast_mut::<crate::backend::Arch>() {
arch.binary = self.config.aur_helper.clone();
arch.aur_rm_args = self.config.aur_rm_args.take();
}
@@ -166,6 +169,7 @@ impl Pacdef {
let mut result = ToDoPerBackend::new();
for mut backend in Backends::iter() {
#[cfg(feature = "arch")]
self.overwrite_values_from_config(&mut *backend);
backend.load(&self.groups);