diff --git a/crates/system-packages/src/deps.rs b/crates/system-packages/src/deps.rs new file mode 100644 index 000000000..3f65be472 --- /dev/null +++ b/crates/system-packages/src/deps.rs @@ -0,0 +1,117 @@ +use crate::env::*; +use crate::error::Error; +use crate::pm::*; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(untagged)] +pub enum DependencyName { + Single(String), + SingleMap(HashMap), + Multiple(Vec), +} + +impl Default for DependencyName { + fn default() -> DependencyName { + DependencyName::Single(String::new()) + } +} + +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] +#[serde(default)] +pub struct DependencyConfig { + pub arch: Option, + pub dep: DependencyName, + pub manager: Option, + // pub optional: bool, + pub os: Option, + pub sudo: bool, + pub version: Option, +} + +impl DependencyConfig { + pub fn get_package_names( + &self, + os: &SystemOS, + pm: &SystemPackageManager, + ) -> Result, Error> { + match &self.dep { + DependencyName::Single(name) => Ok(vec![name.to_owned()]), + DependencyName::SingleMap(map) => map + .get(&pm.to_string()) + .or_else(|| map.get(&os.to_string())) + .or_else(|| map.get("*")) + .map(|name| vec![name.to_owned()]) + .ok_or(Error::MissingName), + DependencyName::Multiple(list) => Ok(list.clone()), + } + } +} + +// This shape is what users configure. +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(untagged)] +pub enum SystemDependency { + Name(String), + Names(Vec), + Config(DependencyConfig), + Map(HashMap), +} + +impl SystemDependency { + pub fn name(name: &str) -> SystemDependency { + SystemDependency::Name(name.to_owned()) + } + + pub fn names(names: I) -> SystemDependency + where + I: IntoIterator, + V: AsRef, + { + SystemDependency::Names(names.into_iter().map(|n| n.as_ref().to_owned()).collect()) + } + + pub fn for_arch(name: &str, arch: SystemArch) -> SystemDependency { + SystemDependency::Config(DependencyConfig { + arch: Some(arch), + dep: DependencyName::Single(name.into()), + ..DependencyConfig::default() + }) + } + + pub fn for_os(name: &str, os: SystemOS) -> SystemDependency { + SystemDependency::Config(DependencyConfig { + dep: DependencyName::Single(name.into()), + os: Some(os), + ..DependencyConfig::default() + }) + } + + pub fn for_os_arch(name: &str, os: SystemOS, arch: SystemArch) -> SystemDependency { + SystemDependency::Config(DependencyConfig { + arch: Some(arch), + dep: DependencyName::Single(name.into()), + os: Some(os), + ..DependencyConfig::default() + }) + } + + pub fn to_config(self) -> DependencyConfig { + match self { + Self::Name(name) => DependencyConfig { + dep: DependencyName::Single(name), + ..DependencyConfig::default() + }, + Self::Names(names) => DependencyConfig { + dep: DependencyName::Multiple(names), + ..DependencyConfig::default() + }, + Self::Map(map) => DependencyConfig { + dep: DependencyName::SingleMap(map), + ..DependencyConfig::default() + }, + Self::Config(config) => config, + } + } +} diff --git a/crates/system-packages/src/lib.rs b/crates/system-packages/src/lib.rs index 981648632..b5e4b66a9 100644 --- a/crates/system-packages/src/lib.rs +++ b/crates/system-packages/src/lib.rs @@ -1,154 +1,13 @@ +mod deps; mod env; mod error; mod pm; mod pm_vendor; +mod system; +pub use deps::*; pub use env::*; pub use error::*; pub use pm::*; pub use pm_vendor::*; - -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; - -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -#[serde(untagged)] -pub enum DependencyName { - Single(String), - SingleMap(HashMap), - Multiple(Vec), -} - -impl Default for DependencyName { - fn default() -> DependencyName { - DependencyName::Single(String::new()) - } -} - -#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] -#[serde(default)] -pub struct DependencyConfig { - pub arch: Option, - pub dep: DependencyName, - pub manager: Option, - // pub optional: bool, - pub os: Option, - pub sudo: bool, - pub version: Option, -} - -impl DependencyConfig { - pub fn get_package_names( - &self, - os: &SystemOS, - pm: &SystemPackageManager, - ) -> Result, Error> { - match &self.dep { - DependencyName::Single(name) => Ok(vec![name.to_owned()]), - DependencyName::SingleMap(map) => map - .get(&pm.to_string()) - .or_else(|| map.get(&os.to_string())) - .or_else(|| map.get("*")) - .map(|name| vec![name.to_owned()]) - .ok_or(Error::MissingName), - DependencyName::Multiple(list) => Ok(list.clone()), - } - } - - pub fn get_package_manager(&self) -> Result { - if let Some(manager) = &self.manager { - return Ok(PackageClient::from(*manager)); - } - - PackageClient::detect() - } -} - -// This shape is what users configure. -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -#[serde(untagged)] -pub enum SystemDependency { - Name(String), - Names(Vec), - Config(DependencyConfig), - Map(HashMap), -} - -impl SystemDependency { - pub fn name(name: &str) -> SystemDependency { - SystemDependency::Name(name.to_owned()) - } - - pub fn names(names: I) -> SystemDependency - where - I: IntoIterator, - V: AsRef, - { - SystemDependency::Names(names.into_iter().map(|n| n.as_ref().to_owned()).collect()) - } - - pub fn for_arch(name: &str, arch: SystemArch) -> SystemDependency { - SystemDependency::Config(DependencyConfig { - arch: Some(arch), - dep: DependencyName::Single(name.into()), - ..DependencyConfig::default() - }) - } - - pub fn for_os(name: &str, os: SystemOS) -> SystemDependency { - SystemDependency::Config(DependencyConfig { - dep: DependencyName::Single(name.into()), - os: Some(os), - ..DependencyConfig::default() - }) - } - - pub fn for_os_arch(name: &str, os: SystemOS, arch: SystemArch) -> SystemDependency { - SystemDependency::Config(DependencyConfig { - arch: Some(arch), - dep: DependencyName::Single(name.into()), - os: Some(os), - ..DependencyConfig::default() - }) - } - - pub fn to_config(self) -> DependencyConfig { - match self { - Self::Name(name) => DependencyConfig { - dep: DependencyName::Single(name), - ..DependencyConfig::default() - }, - Self::Names(names) => DependencyConfig { - dep: DependencyName::Multiple(names), - ..DependencyConfig::default() - }, - Self::Map(map) => DependencyConfig { - dep: DependencyName::SingleMap(map), - ..DependencyConfig::default() - }, - Self::Config(config) => config, - } - } -} - -pub fn resolve_dependencies(deps: Vec) -> Vec { - let os = SystemOS::from_env(); - let arch = SystemArch::from_env(); - let mut configs = vec![]; - - for dep in deps { - let config = dep.to_config(); - - if config.os.as_ref().is_some_and(|o| o != &os) { - continue; - } - - if config.arch.as_ref().is_some_and(|a| a != &arch) { - continue; - } - - configs.push(config); - } - - configs -} +pub use system::*; diff --git a/crates/system-packages/src/pm.rs b/crates/system-packages/src/pm.rs index 13b0bc62a..2ffa91cd2 100644 --- a/crates/system-packages/src/pm.rs +++ b/crates/system-packages/src/pm.rs @@ -1,6 +1,6 @@ use crate::error::Error; +use crate::is_command_on_path; use crate::pm_vendor::*; -use crate::{env::*, DependencyConfig}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -28,36 +28,7 @@ pub enum SystemPackageManager { Scoop, } -impl fmt::Display for SystemPackageManager { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", format!("{:?}", self).to_lowercase()) - } -} - -pub struct PackageClient { - config: VendorConfig, - manager: SystemPackageManager, -} - -impl PackageClient { - pub fn from(manager: SystemPackageManager) -> Self { - Self { - config: match manager { - SystemPackageManager::Apk => apk(), - SystemPackageManager::Apt => apt(), - SystemPackageManager::Dnf => dnf(), - SystemPackageManager::Pacman => pacman(), - SystemPackageManager::Pkg => pkg(), - SystemPackageManager::Pkgin => pkgin(), - SystemPackageManager::Yum => yum(), - SystemPackageManager::Brew => brew(), - SystemPackageManager::Choco => choco(), - SystemPackageManager::Scoop => scoop(), - }, - manager, - } - } - +impl SystemPackageManager { pub fn detect() -> Result { #[cfg(target_os = "linux")] { @@ -66,11 +37,11 @@ impl PackageClient { if let Some(id) = release.lines().find(|l| l.starts_with("ID=")) { return match id[3..].trim_matches('"') { "debian" | "ubuntu" | "pop-os" | "deepin" | "elementary OS" | "kali" - | "linuxmint" => Ok(Self::from(SystemPackageManager::Apt)), - "arch" | "manjaro" => Ok(Self::from(SystemPackageManager::Pacman)), - "centos" | "redhat" | "rhel" => Ok(Self::from(SystemPackageManager::Yum)), - "fedora" => Ok(Self::from(SystemPackageManager::Dnf)), - "alpine" => Ok(Self::from(SystemPackageManager::Apk)), + | "linuxmint" => Ok(SystemPackageManager::Apt), + "arch" | "manjaro" => Ok(SystemPackageManager::Pacman), + "centos" | "redhat" | "rhel" => Ok(SystemPackageManager::Yum), + "fedora" => Ok(SystemPackageManager::Dnf), + "alpine" => Ok(SystemPackageManager::Apk), name => Err(Error::UnknownPackageManager(name.to_owned())), }; } @@ -84,107 +55,53 @@ impl PackageClient { ))] { if is_command_on_path("pkg") { - return Ok(Self::from(SystemPackageManager::Pkg)); + return Ok(SystemPackageManager::Pkg); } if is_command_on_path("pkgin") { - return Ok(Self::from(SystemPackageManager::Pkgin)); + return Ok(SystemPackageManager::Pkgin); } } #[cfg(target_os = "macos")] { if is_command_on_path("brew") { - return Ok(Self::from(SystemPackageManager::Brew)); + return Ok(SystemPackageManager::Brew); } } #[cfg(target_os = "windows")] { if is_command_on_path("choco") { - return Ok(Self::from(SystemPackageManager::Choco)); + return Ok(SystemPackageManager::Choco); } if is_command_on_path("scoop") { - return Ok(Self::from(SystemPackageManager::Scoop)); + return Ok(SystemPackageManager::Scoop); } } Err(Error::MissingPackageManager) } - pub fn get_install_command( - &self, - dep_config: &DependencyConfig, - interactive: bool, - ) -> Result, Error> { - let mut args = vec![]; - let host_os = dep_config.os.unwrap_or_default(); - let base_command = self - .config - .commands - .get(&Command::InstallPackage) - .cloned() - .unwrap(); - - for arg in base_command { - if arg == "$" { - for dep in dep_config.get_package_names(&host_os, &self.manager)? { - if let Some(ver) = &dep_config.version { - match &self.config.version_arg { - VersionArgument::None => { - args.push(dep); - } - VersionArgument::Inline(op) => { - args.push(format!("{dep}{op}{ver}")); - } - VersionArgument::Separate(opt) => { - args.push(dep); - args.push(opt.to_owned()); - args.push(ver.to_owned()); - } - }; - } else { - args.push(dep); - } - } - } else { - args.push(arg); - } - } - - self.handle_interactive(Command::InstallPackage, &mut args, interactive); - - Ok(args) - } - - pub fn get_update_index_command(&self, interactive: bool) -> Option> { - if let Some(args) = self.config.commands.get(&Command::UpdateIndex) { - let mut args = args.to_owned(); - - self.handle_interactive(Command::UpdateIndex, &mut args, interactive); - - return Some(args); + pub fn get_config(&self) -> PackageVendorConfig { + match self { + Self::Apk => apk(), + Self::Apt => apt(), + Self::Dnf => dnf(), + Self::Pacman => pacman(), + Self::Pkg => pkg(), + Self::Pkgin => pkgin(), + Self::Yum => yum(), + Self::Brew => brew(), + Self::Choco => choco(), + Self::Scoop => scoop(), } - - None } +} - fn handle_interactive(&self, command: Command, args: &mut Vec, interactive: bool) { - if self.config.prompt_for.contains(&command) { - match &self.config.prompt_arg { - PromptArgument::None => {} - PromptArgument::Interactive(i) => { - if interactive { - args.push(i.to_owned()); - } - } - PromptArgument::Skip(y) => { - if !interactive { - args.push(y.to_owned()); - } - } - }; - } +impl fmt::Display for SystemPackageManager { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", format!("{:?}", self).to_lowercase()) } } diff --git a/crates/system-packages/src/pm_vendor.rs b/crates/system-packages/src/pm_vendor.rs index 821d71dd1..9b69cc666 100644 --- a/crates/system-packages/src/pm_vendor.rs +++ b/crates/system-packages/src/pm_vendor.rs @@ -33,15 +33,15 @@ pub enum VersionArgument { } #[derive(Clone, Debug)] -pub struct VendorConfig { +pub struct PackageVendorConfig { pub commands: HashMap>, pub prompt_arg: PromptArgument, pub prompt_for: Vec, pub version_arg: VersionArgument, } -pub fn apk() -> VendorConfig { - VendorConfig { +pub fn apk() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ (Command::InstallPackage, string_vec!["apk", "add", "$"]), (Command::UpdateIndex, string_vec!["apk", "update"]), @@ -52,8 +52,8 @@ pub fn apk() -> VendorConfig { } } -pub fn apt() -> VendorConfig { - VendorConfig { +pub fn apt() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ ( Command::InstallPackage, @@ -67,8 +67,8 @@ pub fn apt() -> VendorConfig { } } -pub fn brew() -> VendorConfig { - VendorConfig { +pub fn brew() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ (Command::InstallPackage, string_vec!["brew", "install", "$"]), (Command::UpdateIndex, string_vec!["brew", "update"]), @@ -79,8 +79,8 @@ pub fn brew() -> VendorConfig { } } -pub fn choco() -> VendorConfig { - VendorConfig { +pub fn choco() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([( Command::InstallPackage, string_vec!["choco", "install", "$"], @@ -91,8 +91,8 @@ pub fn choco() -> VendorConfig { } } -pub fn dnf() -> VendorConfig { - VendorConfig { +pub fn dnf() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ (Command::InstallPackage, string_vec!["dnf", "install", "$"]), (Command::UpdateIndex, string_vec!["dnf", "check-update"]), @@ -103,8 +103,8 @@ pub fn dnf() -> VendorConfig { } } -pub fn pacman() -> VendorConfig { - VendorConfig { +pub fn pacman() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ (Command::InstallPackage, string_vec!["pacman", "-S", "$"]), (Command::UpdateIndex, string_vec!["pacman", "-Syy"]), @@ -115,8 +115,8 @@ pub fn pacman() -> VendorConfig { } } -pub fn pkg() -> VendorConfig { - VendorConfig { +pub fn pkg() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ (Command::InstallPackage, string_vec!["pkg", "install", "$"]), (Command::UpdateIndex, string_vec!["pkg", "update"]), @@ -127,8 +127,8 @@ pub fn pkg() -> VendorConfig { } } -pub fn pkg_alt() -> VendorConfig { - VendorConfig { +pub fn pkg_alt() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([(Command::InstallPackage, string_vec!["pkg_add", "$"])]), prompt_arg: PromptArgument::Skip("-I".into()), prompt_for: vec![Command::InstallPackage], @@ -136,8 +136,8 @@ pub fn pkg_alt() -> VendorConfig { } } -pub fn pkgin() -> VendorConfig { - VendorConfig { +pub fn pkgin() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ ( Command::InstallPackage, @@ -151,8 +151,8 @@ pub fn pkgin() -> VendorConfig { } } -pub fn scoop() -> VendorConfig { - VendorConfig { +pub fn scoop() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ ( Command::InstallPackage, @@ -166,8 +166,8 @@ pub fn scoop() -> VendorConfig { } } -pub fn yum() -> VendorConfig { - VendorConfig { +pub fn yum() -> PackageVendorConfig { + PackageVendorConfig { commands: HashMap::from_iter([ (Command::InstallPackage, string_vec!["yum", "install", "$"]), (Command::UpdateIndex, string_vec!["yum", "check-update"]), diff --git a/crates/system-packages/src/system.rs b/crates/system-packages/src/system.rs new file mode 100644 index 000000000..49f3429cf --- /dev/null +++ b/crates/system-packages/src/system.rs @@ -0,0 +1,129 @@ +use crate::deps::{DependencyConfig, SystemDependency}; +use crate::env::*; +use crate::error::Error; +use crate::pm::*; +use crate::pm_vendor::*; + +pub struct System { + pub arch: SystemArch, + pub manager: SystemPackageManager, + pub os: SystemOS, +} + +impl System { + pub fn new() -> Result { + Ok(System::with_manager(SystemPackageManager::detect()?)) + } + + pub fn with_manager(manager: SystemPackageManager) -> Self { + System { + arch: SystemArch::from_env(), + manager, + os: SystemOS::from_env(), + } + } + + pub fn get_install_package_command( + &self, + dep_config: &DependencyConfig, + interactive: bool, + ) -> Result, Error> { + let os = dep_config.os.unwrap_or(self.os); + let pm = dep_config.manager.unwrap_or(self.manager); + let pm_config = pm.get_config(); + let mut args = vec![]; + + for arg in pm_config + .commands + .get(&Command::InstallPackage) + .cloned() + .unwrap() + { + if arg == "$" { + for dep in dep_config.get_package_names(&os, &pm)? { + if let Some(ver) = &dep_config.version { + match &pm_config.version_arg { + VersionArgument::None => { + args.push(dep); + } + VersionArgument::Inline(op) => { + args.push(format!("{dep}{op}{ver}")); + } + VersionArgument::Separate(opt) => { + args.push(dep); + args.push(opt.to_owned()); + args.push(ver.to_owned()); + } + }; + } else { + args.push(dep); + } + } + } else { + args.push(arg); + } + } + + self.append_interactive(Command::InstallPackage, &pm_config, &mut args, interactive); + + Ok(args) + } + + pub fn get_update_index_command(&self, interactive: bool) -> Option> { + let pm_config = self.manager.get_config(); + + if let Some(args) = pm_config.commands.get(&Command::UpdateIndex) { + let mut args = args.to_owned(); + + self.append_interactive(Command::UpdateIndex, &pm_config, &mut args, interactive); + + return Some(args); + } + + None + } + + pub fn resolve_dependencies(&self, deps: Vec) -> Vec { + let mut configs = vec![]; + + for dep in deps { + let config = dep.to_config(); + + if config.os.as_ref().is_some_and(|o| o != &self.os) { + continue; + } + + if config.arch.as_ref().is_some_and(|a| a != &self.arch) { + continue; + } + + configs.push(config); + } + + configs + } + + fn append_interactive( + &self, + command: Command, + config: &PackageVendorConfig, + args: &mut Vec, + interactive: bool, + ) { + if config.prompt_for.contains(&command) { + match &config.prompt_arg { + PromptArgument::None => {} + PromptArgument::Interactive(i) => { + if interactive { + args.push(i.to_owned()); + } + } + PromptArgument::Skip(y) => { + if !interactive { + args.push(y.to_owned()); + } + } + }; + } + } +} diff --git a/crates/system-packages/tests/pm_test.rs b/crates/system-packages/tests/pm_test.rs index 8b7ce0edd..47fe0bb6a 100644 --- a/crates/system-packages/tests/pm_test.rs +++ b/crates/system-packages/tests/pm_test.rs @@ -16,43 +16,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Apk); + let pm = System::with_manager(SystemPackageManager::Apk); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["apk", "add", "foo"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["apk", "add", "foo", "-i"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["apk", "add", "foo", "bar", "baz"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["apk", "add", "foo", "bar", "baz", "-i"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Apk); + let pm = System::with_manager(SystemPackageManager::Apk); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["apk", "add", "foo=1.2.3"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Apk); + let pm = System::with_manager(SystemPackageManager::Apk); assert_eq!( pm.get_update_index_command(false).unwrap(), @@ -70,20 +70,20 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Apt); + let pm = System::with_manager(SystemPackageManager::Apt); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["apt", "install", "--install-recommends", "foo", "-y"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["apt", "install", "--install-recommends", "foo"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec![ "apt", "install", @@ -95,7 +95,7 @@ mod pm { ] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec![ "apt", "install", @@ -109,19 +109,19 @@ mod pm { #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Apt); + let pm = System::with_manager(SystemPackageManager::Apt); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["apt", "install", "--install-recommends", "foo=1.2.3", "-y"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Apt); + let pm = System::with_manager(SystemPackageManager::Apt); assert_eq!( pm.get_update_index_command(false).unwrap(), @@ -139,43 +139,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Brew); + let pm = System::with_manager(SystemPackageManager::Brew); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["brew", "install", "foo"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["brew", "install", "foo", "-i"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["brew", "install", "foo", "bar", "baz"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["brew", "install", "foo", "bar", "baz", "-i"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Brew); + let pm = System::with_manager(SystemPackageManager::Brew); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["brew", "install", "foo@1.2.3"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Brew); + let pm = System::with_manager(SystemPackageManager::Brew); assert_eq!( pm.get_update_index_command(false).unwrap(), @@ -193,43 +193,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Choco); + let pm = System::with_manager(SystemPackageManager::Choco); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["choco", "install", "foo", "-y"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["choco", "install", "foo"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["choco", "install", "foo", "bar", "baz", "-y"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["choco", "install", "foo", "bar", "baz"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Choco); + let pm = System::with_manager(SystemPackageManager::Choco); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["choco", "install", "foo", "--version", "1.2.3", "-y"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Choco); + let pm = System::with_manager(SystemPackageManager::Choco); assert_eq!(pm.get_update_index_command(false), None); } @@ -240,43 +240,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Dnf); + let pm = System::with_manager(SystemPackageManager::Dnf); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["dnf", "install", "foo", "-y"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["dnf", "install", "foo"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["dnf", "install", "foo", "bar", "baz", "-y"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["dnf", "install", "foo", "bar", "baz"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Dnf); + let pm = System::with_manager(SystemPackageManager::Dnf); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["dnf", "install", "foo-1.2.3", "-y"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Dnf); + let pm = System::with_manager(SystemPackageManager::Dnf); assert_eq!( pm.get_update_index_command(false).unwrap(), @@ -294,43 +294,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Pacman); + let pm = System::with_manager(SystemPackageManager::Pacman); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["pacman", "-S", "foo", "--noconfirm"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["pacman", "-S", "foo"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["pacman", "-S", "foo", "bar", "baz", "--noconfirm"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["pacman", "-S", "foo", "bar", "baz"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Pacman); + let pm = System::with_manager(SystemPackageManager::Pacman); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["pacman", "-S", "foo>=1.2.3", "--noconfirm"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Pacman); + let pm = System::with_manager(SystemPackageManager::Pacman); assert_eq!( pm.get_update_index_command(false).unwrap(), @@ -348,43 +348,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Pkg); + let pm = System::with_manager(SystemPackageManager::Pkg); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["pkg", "install", "foo", "-y"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["pkg", "install", "foo"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["pkg", "install", "foo", "bar", "baz", "-y"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["pkg", "install", "foo", "bar", "baz"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Pkg); + let pm = System::with_manager(SystemPackageManager::Pkg); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["pkg", "install", "foo", "-y"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Pkg); + let pm = System::with_manager(SystemPackageManager::Pkg); assert_eq!( pm.get_update_index_command(false).unwrap(), @@ -402,43 +402,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Pkgin); + let pm = System::with_manager(SystemPackageManager::Pkgin); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["pkgin", "install", "foo", "-y"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["pkgin", "install", "foo"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["pkgin", "install", "foo", "bar", "baz", "-y"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["pkgin", "install", "foo", "bar", "baz"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Pkgin); + let pm = System::with_manager(SystemPackageManager::Pkgin); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["pkgin", "install", "foo-1.2.3", "-y"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Pkgin); + let pm = System::with_manager(SystemPackageManager::Pkgin); assert_eq!( pm.get_update_index_command(false).unwrap(), @@ -456,43 +456,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Scoop); + let pm = System::with_manager(SystemPackageManager::Scoop); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["scoop", "install", "foo"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["scoop", "install", "foo"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["scoop", "install", "foo", "bar", "baz"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["scoop", "install", "foo", "bar", "baz"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Scoop); + let pm = System::with_manager(SystemPackageManager::Scoop); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["scoop", "install", "foo@1.2.3"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Scoop); + let pm = System::with_manager(SystemPackageManager::Scoop); assert_eq!( pm.get_update_index_command(false).unwrap(), @@ -510,43 +510,43 @@ mod pm { #[test] fn install_package() { - let pm = PackageClient::from(SystemPackageManager::Yum); + let pm = System::with_manager(SystemPackageManager::Yum); let one_cfg = one_dep(); let many_cfg = many_dep(); assert_eq!( - pm.get_install_command(&one_cfg, false).unwrap(), + pm.get_install_package_command(&one_cfg, false).unwrap(), vec!["yum", "install", "foo", "-y"] ); assert_eq!( - pm.get_install_command(&one_cfg, true).unwrap(), + pm.get_install_package_command(&one_cfg, true).unwrap(), vec!["yum", "install", "foo"] ); assert_eq!( - pm.get_install_command(&many_cfg, false).unwrap(), + pm.get_install_package_command(&many_cfg, false).unwrap(), vec!["yum", "install", "foo", "bar", "baz", "-y"] ); assert_eq!( - pm.get_install_command(&many_cfg, true).unwrap(), + pm.get_install_package_command(&many_cfg, true).unwrap(), vec!["yum", "install", "foo", "bar", "baz"] ); } #[test] fn install_package_with_version() { - let pm = PackageClient::from(SystemPackageManager::Yum); + let pm = System::with_manager(SystemPackageManager::Yum); let mut cfg = one_dep(); cfg.version = Some("1.2.3".into()); assert_eq!( - pm.get_install_command(&cfg, false).unwrap(), + pm.get_install_package_command(&cfg, false).unwrap(), vec!["yum", "install", "foo-1.2.3", "-y"] ); } #[test] fn update_index() { - let pm = PackageClient::from(SystemPackageManager::Yum); + let pm = System::with_manager(SystemPackageManager::Yum); assert_eq!( pm.get_update_index_command(false).unwrap(),