made it print the output of pacman commands, and install using pacman if the package was found in the repos

i18n
axtloss 3 years ago
parent 4c80755318
commit b063db592b

@ -1,6 +1,8 @@
use git2::Repository;
use std::{fs, path::Path, process::exit};
use serde_json::Value;
use std::process::Command;
use std::io::{Error, ErrorKind};
pub fn clone(pkg: &str) {
let url = format!("https://aur.archlinux.org/{}.git", pkg);
@ -8,20 +10,29 @@ pub fn clone(pkg: &str) {
let homedir = std::env::var("HOME").unwrap();
let cachedir = format!("{}/.cache/ame/{}", homedir, pkg);
let path = Path::new(&cachedir);
let errcode = Command::new("pacman").arg("-Ss").arg(&pkg).status().unwrap();
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();
if errcode.success() {
println!("found {} in repos!", &pkg);
Command::new("sudo").arg("pacman").arg("-S").arg(&pkg).spawn();
} else {
println!("Error, repository {} not found", pkg);
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);
}
}
}

@ -2,9 +2,11 @@ use std::process::Command;
pub fn uninstall(pkg: &str) {
let errstr = format!("Could not remove package {}", pkg);
Command::new("pacman")
Command::new("sudo")
.arg("pacman")
.arg("-R")
.arg(&pkg)
.output()
.spawn()
//.status() TODO: for some reason cant use both .spawn and .status at the same time, need fix
.expect(&errstr);
}

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