cleaned up clone.rs and most code in general

i18n
jnats 3 years ago
parent 6190680f4c
commit 2c25c36823

@ -1,11 +1,12 @@
[package]
name = "ame"
version = "0.1.0"
version = "2.0.0"
authors = [ "jnats <jnats@salyut.one>", "axtlos <axt@lo.s>" ]
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 = "*"
raur = "2.0.2"

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

@ -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 <pkg> - install a package
ame -R <pkg> - remove a package
ame -Syu - system upgrade
ame -Ss <pkg> - search for a package")
}

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

@ -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);
}
Loading…
Cancel
Save