initial commit

i18n
jnats 3 years ago
commit 3b8d2c5d99

1
.gitignore vendored

@ -0,0 +1 @@
/target

@ -0,0 +1,11 @@
[package]
name = "ame"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
git2 = "*"
serde_json = "*"
ureq = "*"

@ -0,0 +1,6 @@
debug:
cargo build
release:
cargo build --release
clean:
rm -rf target/ Cargo.lock

@ -0,0 +1,31 @@
use git2::Repository;
use std::{fs, path::Path, process::exit};
use serde_json::Value;
pub fn clone(pkg: &str) {
let url = format!("https://aur.archlinux.org/{}.git", pkg);
let aurl = format!("https://aur.archlinux.org/packages/{}", pkg);
let ajsurl = format!("https://aur.archlinux.org/rpc/?v=5&type=info&arg={}", pkg);
let homedir = std::env::var("HOME").unwrap();
let cachedir = format!("{}/.cache/ame/{}", homedir, pkg);
let path = Path::new(&cachedir);
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);
}
println!("{}", deps);
}

@ -0,0 +1,7 @@
pub fn help() {
println!("\
Usage:\n
\"ame -S pkg\" - install a package
\"ame -R pkg\" - remove a package\
")
}

@ -0,0 +1,26 @@
mod clone;
mod uninstall;
mod help;
use crate::{clone::clone, help::help, uninstall::uninstall};
use std::{env, process::exit};
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 3 {
help();
exit(0);
}
let oper = &args[1];
if oper == "-S" {
for arg in env::args().skip(2) {
clone(&arg);
}
} else if oper == "-R" {
for arg in env::args().skip(2) {
uninstall(&arg);
}
}
}

@ -0,0 +1,10 @@
use std::process::Command;
pub fn uninstall(pkg: &str) {
let errstr = format!("Could not remove package {}", pkg);
Command::new("pacman")
.arg("-R")
.arg(&pkg)
.output()
.expect(&errstr);
}
Loading…
Cancel
Save