From 104c76efbe070b07d61137a2fbf5ebc805799f83 Mon Sep 17 00:00:00 2001 From: jnats Date: Mon, 4 Oct 2021 20:22:30 +0100 Subject: [PATCH] horrid, awful fix to #4 --- Cargo.toml | 1 + src/mods/inssort.rs | 44 ++++++++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4196068..3952a23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ runas = "*" ansi_term = "*" uwuizer = "*" moins = "*" +regex = "*" diff --git a/src/mods/inssort.rs b/src/mods/inssort.rs index 079b5d5..edd63ce 100644 --- a/src/mods/inssort.rs +++ b/src/mods/inssort.rs @@ -4,21 +4,41 @@ use std::process::{Command, Stdio}; pub fn inssort(noconfirm: bool, pkgs: Vec) { let mut repo = vec![]; let mut aur = vec![]; + let re = regex::Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap(); + let reg = regex::Regex::new(r"((?:>=|<=)\S+$)").unwrap(); for pkg in pkgs { - let out = Command::new("pacman") - .arg("-Ss") - .arg(format!("^{}$", &pkg)) - .stdout(Stdio::null()) - .status() - .expect("Something has gone wrong."); - match out.code() { - Some(0) => repo.push(pkg), - Some(1) => aur.push(pkg), - Some(_) => err_unrec(format!("Something has gone terribly wrong")), - None => err_unrec(format!("Process terminated")), + let caps = re.captures(&pkg); + match caps { + Some(_) => { + let out = Command::new("pacman") + .arg("-Ss") + .arg(format!("^{}$", caps.unwrap().get(1).map_or("", |m| m.as_str()))) + .stdout(Stdio::null()) + .status() + .expect("Something has gone wrong."); + match out.code() { + Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()), + Some(1) => aur.push(pkg), + Some(_) => err_unrec(format!("Something has gone terribly wrong")), + None => err_unrec(format!("Process terminated")), + } + } + None => { + let out = Command::new("pacman") + .arg("-Ss") + .arg(format!("^{}$", &pkg)) + .stdout(Stdio::null()) + .status() + .expect("Something has gone wrong."); + match out.code() { + Some(0) => repo.push(pkg), + Some(1) => aur.push(pkg), + Some(_) => err_unrec(format!("Something has gone terribly wrong")), + None => err_unrec(format!("Process terminated")), + } + } } } - if repo.len() != 0 { sec(format!("Installing repo packages: {}", &repo.join(", "))); install(noconfirm, &repo.join(" "));