can now properly install from repos and aur

i18n
axtloss 3 years ago
parent 85c02b91af
commit e88e0e0950

@ -10,3 +10,4 @@ description = "a fast and efficient aur helper."
[dependencies] [dependencies]
git2 = "*" git2 = "*"
raur = "2.0.2" raur = "2.0.2"
runas = "*"

@ -6,12 +6,10 @@ pub fn clone(pkg: &str) {
let error = format!("Couldn't install {}", &pkg); let error = format!("Couldn't install {}", &pkg);
let path = Path::new(&cachedir); let path = Path::new(&cachedir);
let results = raur::search(&pkg).expect(&error); 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() { if path.exists() {
fs::remove_dir_all(path).unwrap(); fs::remove_dir_all(path).unwrap();
} }
for _res in results.first() {
println!("Cloning {} ...", pkg); println!("Cloning {} ...", pkg);
Repository::clone(&url, &path).unwrap(); Repository::clone(&url, &path).unwrap();
println!("Installing {} ...", pkg); println!("Installing {} ...", pkg);
@ -19,7 +17,6 @@ pub fn clone(pkg: &str) {
.current_dir(&cachedir) .current_dir(&cachedir)
.arg("--noconfirm") .arg("--noconfirm")
.arg("-si") .arg("-si")
.output() .status()
.expect(&error); .expect(&error);
}
} }

@ -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);
}

@ -1,14 +1,16 @@
mod clone;
mod uninstall; mod uninstall;
mod help; mod help;
mod upgrade; mod upgrade;
mod search; mod search;
mod clearcache; mod clearcache;
use crate::{clone::clone, help::help, uninstall::uninstall, upgrade::upgrade, search::a_search, search::r_search, clearcache::clearcache}; mod install;
use std::{env, process::exit}; 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() { fn main() {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() <= 1 { if args.len() <= 1 {
help(); help();
exit(1); exit(1);
@ -16,8 +18,13 @@ fn main() {
let oper = &args[1]; let oper = &args[1];
if oper == "-S" { if oper == "-S" {
for arg in env::args().skip(2) { for arg in env::args().skip(2) {
let out = Command::new("pacman").arg("-Ss").arg(&arg).status().unwrap();
if out.success() {
install(&arg);
} else {
clone(&arg); clone(&arg);
} }
}
} else if oper == "-R" { } else if oper == "-R" {
for arg in env::args().skip(2) { for arg in env::args().skip(2) {
uninstall(&arg); uninstall(&arg);

@ -12,7 +12,6 @@ pub fn r_search(pkg: &str) {
Command::new("pacman") Command::new("pacman")
.arg("-Ss") .arg("-Ss")
.arg(&pkg) .arg(&pkg)
.spawn() .status()
//.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix
.expect(&errstr); .expect(&errstr);
} }

@ -7,7 +7,6 @@ pub fn uninstall(pkg: &str) {
.arg("-R") .arg("-R")
.arg("--noconfirm") .arg("--noconfirm")
.arg(&pkg) .arg(&pkg)
.spawn() .status()
//.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix
.expect(&errstr); .expect(&errstr);
} }

@ -4,7 +4,6 @@ pub fn upgrade() {
let errstr = format!("Something happened"); let errstr = format!("Something happened");
Command::new("pacman") Command::new("pacman")
.arg("-Syu") .arg("-Syu")
.spawn() .status()
//.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix
.expect(&errstr); .expect(&errstr);
} }
Loading…
Cancel
Save