added proper cleaning to the sort process + a workaround for me on windows

i18n
michal 2 years ago
parent e7e107bd46
commit 0e7e086f55

@ -9,5 +9,6 @@ description = "A fast and efficient aur helper."
[dependencies]
clap = "2.34.0"
regex = "1.5.4"
reqwest = { version = "0.11.7", default-features = false, features = [ "blocking", "json", "default-tls" ] }
serde = { version = "1.0.90", default-features = false, features = [ "derive" ] }

@ -0,0 +1,22 @@
use regex::Regex;
pub fn clean(a: &[String], verbosity: i32) -> Vec<String> {
let r = Regex::new(r"(\S+)((?:>=|<=|>|<|=>|=<)\S+$)").unwrap();
let mut cleaned: Vec<String> = vec![];
for b in a {
if r.captures_iter(b).count() > 0 {
let c = r.captures(b).unwrap().get(1).map_or("", |m| m.as_str());
cleaned.push(c.to_string());
} else {
cleaned.push(b.to_string());
}
}
if verbosity >= 1 {
eprintln!("Cleaned {:?}\nInto: {:?}", a, cleaned);
}
cleaned
}

@ -1,9 +1,12 @@
mod clean;
pub mod rpc;
pub mod structs;
mod sort;
pub mod structs;
pub fn sort(a: &[String], verbosity: i32) -> structs::Sorted {
sort::sort(a, verbosity)
}
pub fn clean(a: &[String], verbosity: i32) -> Vec<String> {
clean::clean(a, verbosity)
}

@ -1,12 +1,14 @@
use crate::internal::{rpc, structs};
use crate::internal::{clean, rpc, structs};
use std::process::{Command, Stdio};
pub fn sort(a: &[String], verbosity: i32) -> structs::Sorted {
pub fn sort(input: &[String], verbosity: i32) -> structs::Sorted {
#[allow(unused_mut)]
let mut repo: Vec<String> = vec![];
let mut aur: Vec<String> = vec![];
let mut nf: Vec<String> = vec![];
let a = clean(input, verbosity);
match verbosity {
0 => {}
1 => {
@ -15,13 +17,14 @@ pub fn sort(a: &[String], verbosity: i32) -> structs::Sorted {
}
_ => {
eprintln!("Sorting:");
for b in a {
for b in &a {
eprintln!("{:?}", b);
}
}
}
for b in a {
#[cfg(linux)]
let rs = Command::new("pacman")
.arg("-Ss")
.arg(format!("^{}$", &b))
@ -29,6 +32,16 @@ pub fn sort(a: &[String], verbosity: i32) -> structs::Sorted {
.status()
.expect("Something has gone wrong.");
#[cfg(windows)]
let rs = Command::new("pwsh")
.arg("-nop")
.arg("-c")
.arg("exit")
.arg("1")
.stdout(Stdio::null())
.status()
.expect("Something has gone wrong.");
if rpc::rpcinfo(b.to_string()).found {
if verbosity >= 1 {
eprintln!("{} found in AUR.", b);

Loading…
Cancel
Save