diff --git a/Cargo.toml b/Cargo.toml index 650969e..255bf00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "ame" -version = "0.1.0" +version = "2.0.0" +authors = [ "jnats ", "axtlos " ] edition = "2018" +description = "a fast and efficient aur helper." # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] git2 = "*" -ureq = "*" -raur = "*" \ No newline at end of file +raur = "2.0.2" \ No newline at end of file diff --git a/src/clone.rs b/src/clone.rs index 76d6bc2..2ab869c 100644 --- a/src/clone.rs +++ b/src/clone.rs @@ -1,36 +1,20 @@ use git2::Repository; -use std::{fs, path::Path, process::exit}; -use std::process::Command; +use std::{fs, path::Path}; pub fn clone(pkg: &str) { - let url = format!("https://aur.archlinux.org/{}.git", pkg); - let aurl = format!("https://aur.archlinux.org/packages/{}", pkg); - let homedir = std::env::var("HOME").unwrap(); - let cachedir = format!("{}/.cache/ame/{}", homedir, pkg); + let cachedir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg); + let error = format!("Package {} not found.", &pkg); let path = Path::new(&cachedir); - let errcode = Command::new("pacman").arg("-Ss").arg(&pkg).status().unwrap(); + let results = raur::search(&pkg).expect(&error); + let url = format!("https://aur.archlinux.org/{}.git", &pkg); - if errcode.success() { - println!("Found {} in repos...", &pkg); - Command::new("sudo").arg("pacman").arg("-S").arg(&pkg).spawn(); - - } else { - println!("Error"); - - if path.exists() { - fs::remove_dir_all(path).unwrap(); - } - - let aresp = ureq::get(&aurl).call().unwrap_or_else(|error| { - println!("{}", error); - exit(1); - }); - - if aresp.status() == 200 { - println!("Cloning {} ...", pkg); - Repository::clone(&url, &path).unwrap(); - } else { - println!("Error, repository {} not found", pkg); - } + if path.exists() { + fs::remove_dir_all(path).unwrap(); + } + + for _res in results.first() { + println!("Cloning {} ...", pkg); + Repository::clone(&url, &path).unwrap(); } } + diff --git a/src/help.rs b/src/help.rs index 0c56ee3..f9632a9 100644 --- a/src/help.rs +++ b/src/help.rs @@ -1,9 +1,8 @@ pub fn help() { println!("\ Usage:\n -\"ame -S pkg\" - install a package -\"ame -R pkg\" - remove a package -\"ame -Syu\" - upgrade a package -\"ame -Ss\" - search for a package - ") +ame -S - install a package +ame -R - remove a package +ame -Syu - system upgrade +ame -Ss - search for a package") } diff --git a/src/main.rs b/src/main.rs index c888874..a7ea3b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod uninstall; mod help; mod upgrade; mod search; -use crate::{clone::clone, help::help, uninstall::uninstall, upgrade::upgrade, search::search}; +use crate::{clone::clone, help::help, uninstall::uninstall, upgrade::upgrade, search::a_search, search::r_search}; use std::{env, process::exit}; fn main() { @@ -25,7 +25,16 @@ fn main() { upgrade(); } else if oper == "-Ss" { for arg in env::args().skip(2) { - search(&arg); + r_search(&arg); + a_search(&arg); + } + } else if oper == "-Sa" { + for arg in env::args().skip(2) { + a_search(&arg); + } + } else if oper == "-Sr" { + for arg in env::args().skip(2) { + r_search(&arg); } } else { help(); diff --git a/src/search.rs b/src/search.rs index d0941bc..5dd24a9 100644 --- a/src/search.rs +++ b/src/search.rs @@ -1,8 +1,19 @@ -use std::ops::Deref; +use std::{ops::Deref, process::Command}; -pub fn search(pkg: &str) { +pub fn a_search(pkg: &str) { let results = raur::search(&pkg); for res in &results { println!("{} {}\n {}", res[0].name, res[0].version, res[0].description.as_ref().map_or("n/a", String::deref)); } + println!("{:#?}", results); +} + +pub fn r_search(pkg: &str) { + let errstr = format!("Something happened"); + Command::new("pacman") + .arg("-Ss") + .arg(&pkg) + .spawn() + //.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix + .expect(&errstr); } \ No newline at end of file