diff --git a/Cargo.lock b/Cargo.lock index fdbcf78..d58ddd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,217 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "libc" +version = "0.2.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" + +[[package]] +name = "linux-raw-sys" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "rustix" +version = "0.38.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "upt" version = "0.3.0" +dependencies = [ + "which", +] + +[[package]] +name = "which" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bf3ea8596f3a0dd5980b46430f2058dfe2c36a27ccfbb1845d6fbfcd9ba6e14" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", + "windows-sys 0.48.0", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/Cargo.toml b/Cargo.toml index 9a4cc35..ea18f0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,9 @@ repository = "https://github.com/sigoden/upt" categories = ["command-line-utilities"] keywords = ["universal", "package", "management"] +[dependencies] +which = "5.0.0" + [[bin]] doc = false name = "upt" @@ -17,4 +20,4 @@ name = "upt" [profile.release] lto = true strip = true -opt-level = "z" \ No newline at end of file +opt-level = "z" diff --git a/src/subcommand.rs b/src/action.rs similarity index 67% rename from src/subcommand.rs rename to src/action.rs index bddff07..f36e908 100644 --- a/src/subcommand.rs +++ b/src/action.rs @@ -4,14 +4,14 @@ use std::cell::Cell; use std::str::FromStr; #[derive(Debug, Clone, PartialEq, Default)] -pub(crate) struct SubCommand { +pub(crate) struct Action { cmd: String, action: Option, has_pkg: bool, options: Vec>, } -impl FromStr for SubCommand { +impl FromStr for Action { type Err = UptError; fn from_str(s: &str) -> Result { if s.is_empty() { @@ -21,7 +21,7 @@ impl FromStr for SubCommand { let mut has_pkg = false; let mut options: Vec> = vec![]; if words.len() < 2 { - return Err(UptError::InvalidSubcommand(s.to_string())); + return Err(UptError::InvalidAction(s.to_string())); } let (cmd, action, reminder) = if words[1].starts_with('-') || words[1] == "$" { (words[0].to_string(), None, &words[1..]) @@ -44,7 +44,7 @@ impl FromStr for SubCommand { options.push(split(elem)); } } - Ok(SubCommand { + Ok(Action { cmd, action, has_pkg, @@ -53,10 +53,10 @@ impl FromStr for SubCommand { } } -impl SubCommand { +impl Action { /// Try to parse the command line arguemnts pub fn parse(&self, args: &[String], confirm: &str) -> Option<(Option, bool)> { - if self.is_default() { + if self.invalid() { return None; } let (options, pkg) = self.parse_args(args)?; @@ -77,7 +77,7 @@ impl SubCommand { } pub fn to_cmd(&self, pkg: &str, confirm: &str) -> Option { - if self.is_default() { + if self.invalid() { return None; } let mut segs: Vec<&str> = vec![&self.cmd]; @@ -98,7 +98,7 @@ impl SubCommand { /// Genereate help message pub fn help(&self) -> Option { - if self.is_default() { + if self.invalid() { return None; } let mut segs: Vec = vec![self.cmd.clone()]; @@ -120,7 +120,7 @@ impl SubCommand { Some(segs.join(" ")) } - fn is_default(&self) -> bool { + fn invalid(&self) -> bool { self == &Default::default() } @@ -181,8 +181,8 @@ impl SubCommand { } /// used in vendor! -pub(crate) fn must_from_str(s: &str, name: &str, field: &str) -> SubCommand { - match SubCommand::from_str(s) { +pub(crate) fn must_from_str(s: &str, name: &str, field: &str) -> Action { + match Action::from_str(s) { Ok(p) => p, Err(_) => panic!("Failed to parse {}.{} from '{}' ", name, field, s), } @@ -190,183 +190,183 @@ pub(crate) fn must_from_str(s: &str, name: &str, field: &str) -> SubCommand { #[cfg(test)] mod tests { - use super::SubCommand; + use super::Action; use std::str::FromStr; - macro_rules! check_subcommand_from_str { + macro_rules! check_action_from_str { ($input:expr, { $cmd:expr, $action:expr, [$([$($options:expr),* $(,)*]),*], $has_pkg:expr }) => { - let subcommand = SubCommand::from_str($input).unwrap(); - let expect_subcommand = SubCommand { + let action = Action::from_str($input).unwrap(); + let expect_action = Action { cmd: $cmd.to_string(), action: $action.map(|v| v.to_string()), has_pkg: $has_pkg, options: vec![$(vec![$($options.to_string(),)*],)*], }; - assert_eq!(subcommand, expect_subcommand); + assert_eq!(action, expect_action); } } #[test] - fn test_subcommand_from_str() { - check_subcommand_from_str!( + fn test_action_from_str() { + check_action_from_str!( "upt install $", { "upt", Some("install"), [], true } ); - check_subcommand_from_str!( + check_action_from_str!( "upt search $", { "upt", Some("search"), [], true } ); - check_subcommand_from_str!( + check_action_from_str!( "apt list --installed", {"apt", Some("list"), [["--installed"]], false } ); - check_subcommand_from_str!( + check_action_from_str!( "pacman -R -s $", { "pacman", None::<&str>, [["-R"], ["-s"]], true } ); - check_subcommand_from_str!( + check_action_from_str!( "pacman -S -y -y", { "pacman", None::<&str>, [["-S"], ["-y"], ["-y"]], false } ); - check_subcommand_from_str!( + check_action_from_str!( "pacman -S $", { "pacman", None::<&str>, [["-S"]], true } ); } - macro_rules! check_subcommand_parse { + macro_rules! check_action_parse { ($input:expr, $confirm:expr, [$($args:expr),*], ($pkg:expr, $confirm_result:expr)) => { { - let subcommand = SubCommand::from_str($input).unwrap(); + let action = Action::from_str($input).unwrap(); let args = vec![$($args.to_string()),*]; let pkg = if $pkg.len() == 0 { None } else { Some($pkg.to_string()) }; - assert_eq!(subcommand.parse(&args, $confirm).unwrap(), (pkg, $confirm_result)); + assert_eq!(action.parse(&args, $confirm).unwrap(), (pkg, $confirm_result)); } }; ($input:expr, $confirm:expr, [$($args:expr),*]) => { { - let subcommand = SubCommand::from_str($input).unwrap(); + let action = Action::from_str($input).unwrap(); let args = vec![ $($args.to_string()),*]; - assert_eq!(subcommand.parse(&args, $confirm), None); + assert_eq!(action.parse(&args, $confirm), None); } } } #[test] - fn test_subcommand_parse() { - check_subcommand_parse!( + fn test_action_parse() { + check_action_parse!( "apt install $", "-y/--confirm", ["apt", "install", "vim"], ("vim", false) ); - check_subcommand_parse!( + check_action_parse!( "apt install $", "-y/--confirm", ["apt", "install", "-y", "vim"], ("vim", true) ); - check_subcommand_parse!( + check_action_parse!( "apt install $", "-y/--confirm", ["apt", "install", "--confirm", "vim"], ("vim", true) ); - check_subcommand_parse!( + check_action_parse!( "apt install $", "-y/--confirm", ["apt", "install", "vim", "jq"], ("vim jq", false) ); - check_subcommand_parse!("apt install $", "-y/--confirm", ["upt", "install", "vim"]); - check_subcommand_parse!("apt search $", "", ["apt", "search", "vim"], ("vim", false)); - check_subcommand_parse!( + check_action_parse!("apt install $", "-y/--confirm", ["upt", "install", "vim"]); + check_action_parse!("apt search $", "", ["apt", "search", "vim"], ("vim", false)); + check_action_parse!( "apt list --installed", "", ["apt", "list", "--installed"], ("", false) ); - check_subcommand_parse!( + check_action_parse!( "pacman -R -s $", "--noconfirm", ["pacman", "-R", "-s", "--noconfirm", "vim"], ("vim", true) ); - check_subcommand_parse!( + check_action_parse!( "pacman -R -s $", "--noconfirm", ["pacman", "-Rs", "vim"], ("vim", false) ); - check_subcommand_parse!( + check_action_parse!( "pacman -R -s $", "--noconfirm", ["pacman", "-Rs", "--noconfirm", "vim", "jq"], ("vim jq", true) ); - check_subcommand_parse!("pacman -S -y -y", "", ["pacman", "-Syy"], ("", false)); - check_subcommand_parse!("pacman -S $", "", ["pacman", "-S", "vim"], ("vim", false)); - check_subcommand_parse!("apt tsearch $", "", ["apt", "search"]); - check_subcommand_parse!("apt tupgrade", "", ["apt", "upgrade", "vim"]); - check_subcommand_parse!("pacman -S -y -y", "", ["pacman", "-Sy"]); - check_subcommand_parse!("pacman -S -y -y", "", ["pacman", "-Syyy"]); - check_subcommand_parse!("pacman -Q -i", "", ["pacman", "-Qiy"]); + check_action_parse!("pacman -S -y -y", "", ["pacman", "-Syy"], ("", false)); + check_action_parse!("pacman -S $", "", ["pacman", "-S", "vim"], ("vim", false)); + check_action_parse!("apt tsearch $", "", ["apt", "search"]); + check_action_parse!("apt tupgrade", "", ["apt", "upgrade", "vim"]); + check_action_parse!("pacman -S -y -y", "", ["pacman", "-Sy"]); + check_action_parse!("pacman -S -y -y", "", ["pacman", "-Syyy"]); + check_action_parse!("pacman -Q -i", "", ["pacman", "-Qiy"]); } - macro_rules! check_subcommand_to_cmd { + macro_rules! check_action_to_cmd { ($input:expr, ($pkg:expr, $confirm:expr), $cmd:expr) => {{ - let subcommand = SubCommand::from_str($input).unwrap(); - assert_eq!(subcommand.to_cmd($pkg, $confirm), Some($cmd.to_string())); + let action = Action::from_str($input).unwrap(); + assert_eq!(action.to_cmd($pkg, $confirm), Some($cmd.to_string())); }}; ($input:expr, ($pkg:expr, $confirm:expr)) => {{ - let subcommand = SubCommand::from_str($input).unwrap(); - assert!(subcommand.to_cmd($pkg, $confirm).is_none()); + let action = Action::from_str($input).unwrap(); + assert!(action.to_cmd($pkg, $confirm).is_none()); }}; } #[test] - fn test_subcommand_to_cmd() { - check_subcommand_to_cmd!("apt install $", ("vim", ""), "apt install vim"); - check_subcommand_to_cmd!("apt install $", ("vim", "-y"), "apt install -y vim"); - check_subcommand_to_cmd!("apt install $", ("vim jq", ""), "apt install vim jq"); - check_subcommand_to_cmd!("apt search $", ("vim", ""), "apt search vim"); - check_subcommand_to_cmd!("apt list --installed", ("", ""), "apt list --installed"); - check_subcommand_to_cmd!( + fn test_action_to_cmd() { + check_action_to_cmd!("apt install $", ("vim", ""), "apt install vim"); + check_action_to_cmd!("apt install $", ("vim", "-y"), "apt install -y vim"); + check_action_to_cmd!("apt install $", ("vim jq", ""), "apt install vim jq"); + check_action_to_cmd!("apt search $", ("vim", ""), "apt search vim"); + check_action_to_cmd!("apt list --installed", ("", ""), "apt list --installed"); + check_action_to_cmd!( "pacman -R -s $", ("vim", "--noconfirm"), "pacman -R -s --noconfirm vim" ); - check_subcommand_to_cmd!("pacman -R -s $", ("vim", ""), "pacman -R -s vim"); - check_subcommand_to_cmd!( + check_action_to_cmd!("pacman -R -s $", ("vim", ""), "pacman -R -s vim"); + check_action_to_cmd!( "pacman -R -s $", ("vim jq", "--noconfirm"), "pacman -R -s --noconfirm vim jq" ); - check_subcommand_to_cmd!("pacman -S -y -y", ("", ""), "pacman -S -y -y"); - check_subcommand_to_cmd!("pacman -S $", ("vim", ""), "pacman -S vim"); + check_action_to_cmd!("pacman -S -y -y", ("", ""), "pacman -S -y -y"); + check_action_to_cmd!("pacman -S $", ("vim", ""), "pacman -S vim"); } - macro_rules! check_subcommand_help { + macro_rules! check_action_help { ($input:expr, $help:expr) => {{ - let subcommand = SubCommand::from_str($input).unwrap(); - assert_eq!(subcommand.help(), Some($help.to_string())); + let action = Action::from_str($input).unwrap(); + assert_eq!(action.help(), Some($help.to_string())); }}; ($input:expr) => {{ - let subcommand = SubCommand::from_str($input).unwrap(); - assert!(subcommand.help().is_none()); + let action = Action::from_str($input).unwrap(); + assert!(action.help().is_none()); }}; } #[test] - fn test_subcommand_help() { - check_subcommand_help!("upt install $", "upt install "); - check_subcommand_help!("upt search $", "upt search "); - check_subcommand_help!("upt list -i/--installed", "upt list -i/--installed"); - check_subcommand_help!("pacman -S -y -y", "pacman -S -y -y"); - check_subcommand_help!("pacman -S $", "pacman -S "); + fn test_action_help() { + check_action_help!("upt install $", "upt install "); + check_action_help!("upt search $", "upt search "); + check_action_help!("upt list -i/--installed", "upt list -i/--installed"); + check_action_help!("pacman -S -y -y", "pacman -S -y -y"); + check_action_help!("pacman -S $", "pacman -S "); } } diff --git a/src/error.rs b/src/error.rs index 6516ede..d660f5c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,10 +4,9 @@ use std::fmt; #[derive(Debug, PartialEq)] pub enum UptError { NoVendor(String), - NotSupportOS, - NotSupportTask, + NoTask, NotFoundTool, - InvalidSubcommand(String), + InvalidAction(String), InvalidArgs(String), DisplyHelp(String), } @@ -18,14 +17,13 @@ impl fmt::Display for UptError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use UptError::*; match self { - NoVendor(v) => write!(f, "Vendor {} is not supported.", v), - NotSupportOS => write!(f, "Your OS is not supported currently."), - NotSupportTask => write!(f, "The task is not supported by your OS."), + NoVendor(v) => write!(f, "The vendor {} is not supported.", v), + NoTask => write!(f, "The package management tool cannot perform the task."), NotFoundTool => write!( f, "No found package management tool, use `$UPT_TOOL` to specify one." ), - InvalidSubcommand(v) => write!(f, "Invalid subcommand '{}'.", v), + InvalidAction(v) => write!(f, "Invalid action '{}'.", v), InvalidArgs(v) => write!(f, "Invalid arguments.\n\n{}", v), DisplyHelp(v) => write!(f, "{}", v), } diff --git a/src/lib.rs b/src/lib.rs index ca2cdbd..020178a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ #[macro_use] mod macros; +mod action; mod error; -mod subcommand; mod task; mod utils; mod vendor; diff --git a/src/macros.rs b/src/macros.rs index a26cf1e..856c5f3 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -16,7 +16,7 @@ macro_rules! vendors { )+ ) => { pub fn init(name: &str) -> Result<$crate::Vendor, $crate::UptError> { - use $crate::subcommand::must_from_str; + use $crate::action::must_from_str; match name { $( $name => { @@ -61,7 +61,7 @@ macro_rules! vendors { macro_rules! os_tools { ($($os:literal => $($tool:literal),+);+$(;)?) => { pub fn detect_tool() -> std::result::Result<$crate::Vendor, $crate::UptError> { - let os = crate::utils::detect_os().ok_or(UptError::NotSupportOS)?; + let os = crate::utils::detect_os().unwrap_or_default(); let tools: Vec<&str> = match os.as_str() { $( $os => vec![$($tool),+].into_iter().filter_map(|v| which_cmd(v)).collect(), diff --git a/src/utils.rs b/src/utils.rs index 4a58c6f..3a5d8af 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,19 +1,11 @@ -use std::process::{Command, Stdio}; - -pub fn which(name: &str) -> bool { - Command::new(name) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .spawn() - .is_ok() -} +use which::which; pub fn find_tool(tools: &[&str]) -> Option { match tools.len() { 0 => None, 1 => { let tool = &tools[0]; - if which(tool) { + if which(tool).is_ok() { Some(tool.to_string()) } else { None @@ -24,7 +16,13 @@ pub fn find_tool(tools: &[&str]) -> Option { .iter() .map(|tool| { let tool = tool.to_string(); - std::thread::spawn(move || if which(&tool) { Some(tool) } else { None }) + std::thread::spawn(move || { + if which(&tool).is_ok() { + Some(tool) + } else { + None + } + }) }) .collect(); for handle in handles { diff --git a/src/vendor.rs b/src/vendor.rs index dcace8a..99e4571 100644 --- a/src/vendor.rs +++ b/src/vendor.rs @@ -1,5 +1,5 @@ +use crate::action::Action; use crate::error::UptError; -use crate::subcommand::SubCommand; use crate::task::Task; os_tools!( @@ -368,14 +368,14 @@ vendors![ pub struct Vendor { pub(crate) name: String, pub(crate) confirm: String, - pub(crate) install: SubCommand, - pub(crate) remove: SubCommand, - pub(crate) upgrade: SubCommand, - pub(crate) search: SubCommand, - pub(crate) info: SubCommand, - pub(crate) update_index: SubCommand, - pub(crate) upgrade_all: SubCommand, - pub(crate) list_installed: SubCommand, + pub(crate) install: Action, + pub(crate) remove: Action, + pub(crate) upgrade: Action, + pub(crate) search: Action, + pub(crate) info: Action, + pub(crate) update_index: Action, + pub(crate) upgrade_all: Action, + pub(crate) list_installed: Action, } impl Vendor { @@ -423,7 +423,7 @@ impl Vendor { Task::UpgradeAll { confirm: yes } => self.upgrade_all.to_cmd("", self.yes_str(yes)), Task::ListInstalled => self.list_installed.to_cmd("", ""), }; - cmd.ok_or(UptError::NotSupportTask) + cmd.ok_or(UptError::NoTask) } fn yes_str(&self, yes: &bool) -> &str {