From 47b16a7f9097cd848979183093abc700aa6f060b Mon Sep 17 00:00:00 2001 From: amy Date: Sat, 23 Oct 2021 21:25:03 +0200 Subject: [PATCH] now able to install packages from a specific repo by appending the repo to the package ( community/neofetch or aur/nofetch-git ) --- Cargo.toml | 2 +- src/mods/inssort.rs | 83 +++++++++++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4887590..2366cda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ame" -version = "0.0.0" +version = "2.4.1" authors = [ "jnats ", "axtlos " ] edition = "2018" description = "a fast and efficient aur helper." diff --git a/src/mods/inssort.rs b/src/mods/inssort.rs index 66b03c7..eb4c39b 100644 --- a/src/mods/inssort.rs +++ b/src/mods/inssort.rs @@ -8,37 +8,62 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec) { let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap(); let reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap(); for pkg in pkgs { - 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")), + match pkg.contains("/") { + true => { + match pkg.split("/").collect::>()[0] == "aur" { + true => { + aur.push(pkg.split("/").collect::>()[1].to_string()); + } + false => { + let out = Command::new("bash") + .arg("-c") + .arg(format!("pacman -Sl {} | grep {}", pkg.split("/").collect::>()[0],pkg.split("/").collect::>()[1])) + .stdout(Stdio::null()) + .status() + .expect("Something has gone wrong."); + match out.code() { + Some(0) => repo.push(reg.replace_all(&pkg, "").to_string()), + Some(1) => err_unrec(format!("Package {} not found in repository {}", pkg.split("/").collect::>()[1],pkg.split("/").collect::>()[0])), + 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")), + false => { + 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")), + } + } } } }