diff --git a/Cargo.toml b/Cargo.toml index 79508e1..84e6926 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" ] } \ No newline at end of file diff --git a/src/internal/clean.rs b/src/internal/clean.rs new file mode 100644 index 0000000..46ffe23 --- /dev/null +++ b/src/internal/clean.rs @@ -0,0 +1,22 @@ +use regex::Regex; + +pub fn clean(a: &[String], verbosity: i32) -> Vec { + let r = Regex::new(r"(\S+)((?:>=|<=|>|<|=>|=<)\S+$)").unwrap(); + + let mut cleaned: Vec = 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 +} diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 4343937..27f2af2 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -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 { + clean::clean(a, verbosity) +} diff --git a/src/internal/sort.rs b/src/internal/sort.rs index 3930f0c..0596360 100644 --- a/src/internal/sort.rs +++ b/src/internal/sort.rs @@ -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 = vec![]; let mut aur: Vec = vec![]; let mut nf: Vec = 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);