diff --git a/Cargo.toml b/Cargo.toml index 255bf00..d0af7b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,5 @@ description = "a fast and efficient aur helper." [dependencies] git2 = "*" -raur = "2.0.2" \ No newline at end of file +raur = "2.0.2" +runas = "*" \ No newline at end of file diff --git a/src/clearcache.rs b/src/clearcache.rs index 13b6129..7fca292 100644 --- a/src/clearcache.rs +++ b/src/clearcache.rs @@ -5,4 +5,4 @@ pub fn clearcache() { fs::remove_dir_all(&path).unwrap(); fs::create_dir(&path).unwrap(); -} \ No newline at end of file +} diff --git a/src/clone.rs b/src/clone.rs index e8c0e31..1e22e9a 100644 --- a/src/clone.rs +++ b/src/clone.rs @@ -6,20 +6,17 @@ pub fn clone(pkg: &str) { let error = format!("Couldn't install {}", &pkg); let path = Path::new(&cachedir); let results = raur::search(&pkg).expect(&error); - let url = format!("https://aur.archlinux.org/{}.git", &pkg); + let url = format!("https://aur.archlinux.org/{}.git", results[0].name); if path.exists() { fs::remove_dir_all(path).unwrap(); } - - for _res in results.first() { - println!("Cloning {} ...", pkg); - Repository::clone(&url, &path).unwrap(); - println!("Installing {} ...", pkg); - Command::new("makepkg") - .current_dir(&cachedir) - .arg("--noconfirm") - .arg("-si") - .output() - .expect(&error); - } + println!("Cloning {} ...", pkg); + Repository::clone(&url, &path).unwrap(); + println!("Installing {} ...", pkg); + Command::new("makepkg") + .current_dir(&cachedir) + .arg("--noconfirm") + .arg("-si") + .status() + .expect(&error); } diff --git a/src/install.rs b/src/install.rs new file mode 100644 index 0000000..f823980 --- /dev/null +++ b/src/install.rs @@ -0,0 +1,6 @@ +use runas::Command; + +pub fn install(pkg: &str) { + let errstr = format!("Something went wrong"); + Command::new("pacman").arg("-S").arg(&pkg).status().expect(&errstr); +} diff --git a/src/main.rs b/src/main.rs index d002df1..f0d0121 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,16 @@ -mod clone; mod uninstall; mod help; mod upgrade; mod search; mod clearcache; -use crate::{clone::clone, help::help, uninstall::uninstall, upgrade::upgrade, search::a_search, search::r_search, clearcache::clearcache}; -use std::{env, process::exit}; +mod install; +mod clone; +use crate::{clone::clone, help::help, uninstall::uninstall, upgrade::upgrade, search::a_search, search::r_search, clearcache::clearcache, install::install}; +use std::{env, process::exit, process::Command}; fn main() { let args: Vec = env::args().collect(); + if args.len() <= 1 { help(); exit(1); @@ -16,7 +18,12 @@ fn main() { let oper = &args[1]; if oper == "-S" { for arg in env::args().skip(2) { - clone(&arg); + let out = Command::new("pacman").arg("-Ss").arg(&arg).status().unwrap(); + if out.success() { + install(&arg); + } else { + clone(&arg); + } } } else if oper == "-R" { for arg in env::args().skip(2) { @@ -43,4 +50,4 @@ fn main() { help(); exit(0); } -} \ No newline at end of file +} diff --git a/src/search.rs b/src/search.rs index c919017..a60bf67 100644 --- a/src/search.rs +++ b/src/search.rs @@ -12,7 +12,6 @@ pub fn r_search(pkg: &str) { 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 + .status() .expect(&errstr); -} \ No newline at end of file +} diff --git a/src/uninstall.rs b/src/uninstall.rs index 796456b..b7dceac 100644 --- a/src/uninstall.rs +++ b/src/uninstall.rs @@ -7,7 +7,6 @@ pub fn uninstall(pkg: &str) { .arg("-R") .arg("--noconfirm") .arg(&pkg) - .spawn() - //.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix + .status() .expect(&errstr); -} \ No newline at end of file +} diff --git a/src/upgrade.rs b/src/upgrade.rs index 805509d..4764ead 100644 --- a/src/upgrade.rs +++ b/src/upgrade.rs @@ -4,7 +4,6 @@ pub fn upgrade() { let errstr = format!("Something happened"); Command::new("pacman") .arg("-Syu") - .spawn() - //.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix + .status() .expect(&errstr); -} \ No newline at end of file +}