cleaned up clone.rs and most code in general
parent
6190680f4c
commit
2c25c36823
@ -1,11 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ame"
|
name = "ame"
|
||||||
version = "0.1.0"
|
version = "2.0.0"
|
||||||
|
authors = [ "jnats <jnats@salyut.one>", "axtlos <axt@lo.s>" ]
|
||||||
edition = "2018"
|
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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
git2 = "*"
|
git2 = "*"
|
||||||
ureq = "*"
|
raur = "2.0.2"
|
||||||
raur = "*"
|
|
@ -1,36 +1,20 @@
|
|||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use std::{fs, path::Path, process::exit};
|
use std::{fs, path::Path};
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
pub fn clone(pkg: &str) {
|
pub fn clone(pkg: &str) {
|
||||||
let url = format!("https://aur.archlinux.org/{}.git", pkg);
|
let cachedir = format!("{}/.cache/ame/{}", std::env::var("HOME").unwrap(), pkg);
|
||||||
let aurl = format!("https://aur.archlinux.org/packages/{}", pkg);
|
let error = format!("Package {} not found.", &pkg);
|
||||||
let homedir = std::env::var("HOME").unwrap();
|
|
||||||
let cachedir = format!("{}/.cache/ame/{}", homedir, pkg);
|
|
||||||
let path = Path::new(&cachedir);
|
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() {
|
if path.exists() {
|
||||||
println!("Found {} in repos...", &pkg);
|
fs::remove_dir_all(path).unwrap();
|
||||||
Command::new("sudo").arg("pacman").arg("-S").arg(&pkg).spawn();
|
}
|
||||||
|
|
||||||
} else {
|
for _res in results.first() {
|
||||||
println!("Error");
|
println!("Cloning {} ...", pkg);
|
||||||
|
Repository::clone(&url, &path).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();
|
|
||||||
} else {
|
|
||||||
println!("Error, repository {} not found", pkg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
pub fn help() {
|
pub fn help() {
|
||||||
println!("\
|
println!("\
|
||||||
Usage:\n
|
Usage:\n
|
||||||
\"ame -S pkg\" - install a package
|
ame -S <pkg> - install a package
|
||||||
\"ame -R pkg\" - remove a package
|
ame -R <pkg> - remove a package
|
||||||
\"ame -Syu\" - upgrade a package
|
ame -Syu - system upgrade
|
||||||
\"ame -Ss\" - search for a package
|
ame -Ss <pkg> - search for a package")
|
||||||
")
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
let results = raur::search(&pkg);
|
||||||
for res in &results {
|
for res in &results {
|
||||||
println!("{} {}\n {}", res[0].name, res[0].version, res[0].description.as_ref().map_or("n/a", String::deref));
|
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…
Reference in New Issue