fix my messup with testing part 2

i18n
axtlos 3 years ago
parent 1d4b996ae4
commit 05d8940b30

@ -15,3 +15,6 @@ ansi_term = "*"
uwuizer = "*"
moins = "*"
regex = "*"
toml_edit = "*"
toml = "*"
bytes = "*"

@ -0,0 +1,80 @@
mod mods;
use mods::{clearcache::clearcache, clone::clone, help::help, install::install, inssort::inssort, search::{a_search, r_search}, uninstall::uninstall, upgrade::upgrade, update::update, ver::ver, strs::inf, strs::err_unrec, strs::err_rec, xargs::*, database::addPkg};
use std::{env, process::exit, process::Command};
fn main() {
// let statements
let args: Vec<String> = env::args().collect();
let mut pkgs: Vec<String> = env::args().skip(2).collect();
// args catch
if args.len() <= 1 {
help();
exit(1);
}
let oper = &args[1];
let noconfirm: bool = noconf(&args);
argssort(&mut pkgs);
// install
if oper == "-S" || oper == "-Sn" || oper == "ins" {
inssort(noconfirm, pkgs);
// remove
} else if oper == "-R" || oper == "-Rn " || oper == "-Rsn" || oper == "-Rs" || oper == "rm" {
uninstall(noconfirm, pkgs);
// upgrade
} else if oper == "-Syu" || oper == "-Syun" || oper == "upg" {
upgrade(noconfirm);
// update
} else if oper == "-Sy" || oper == "upd" {
update();
} else if oper == "-db" {
addPkg(pkgs);
// general search
} else if oper == "-Ss" || oper == "sea" {
r_search(&args[2]);
a_search(&args[2]);
// aur search
} else if oper == "-Sa" || oper == "aursea" {
a_search(&args[2]);
// repo search
} else if oper == "-Sr" || oper == "repsea" {
r_search(&args[2]);
// clear cache !! DEBUG ONLY !! DO NOT DO THIS IF YOU DONT KNOW WHAT YOURE DOING !!
} else if oper == "-Cc" || oper == "clr" {
clearcache();
// version / contrib
} else if oper == "-v" || oper == "-V" || oper == "ver" {
ver();
// help
} else if oper == "-h" || oper == "help" {
help();
// pacman passthrough
} else {
let pass = Command::new("pacman")
.args(env::args().skip(1))
.status()
.expect("Something has gone wrong.");
match pass.code() {
Some(1) => {
err_rec(format!("No such operation \"{}\"", args.join(" ")));
inf(format!("Try running \"ame help\" for an overview of how to use ame"))
}
Some(_) => {}
None => {
err_unrec(format!("Something has gone terribly wrong."))
}}
}
}

@ -14,6 +14,7 @@ use mods::{
upgrade::upgrade,
ver::ver,
xargs::*,
database::{addPkg, remPkg}
};
use std::{env, process::exit, process::Command};

@ -10,3 +10,4 @@ pub mod update;
pub mod upgrade;
pub mod ver;
pub mod xargs;
pub mod database;

@ -1,6 +1,6 @@
use crate::{
err_unrec, inf, inssort, mods::strs::prompt, mods::strs::sec, mods::strs::succ,
mods::uninstall::uninstall,
mods::uninstall::uninstall, mods::database::addPkg
};
use git2::Repository;
use moins::Moins;
@ -102,6 +102,7 @@ pub fn clone(noconfirm: bool, pkg: &str) {
match install_result {
Ok(_) => {
uninstall_make_depend(pkg);
addPkg(false, pkg);
}
Err(_) => {
err_unrec(format!("Couldn't install {}", pkg));
@ -117,6 +118,7 @@ pub fn clone(noconfirm: bool, pkg: &str) {
match install_result.code() {
Some(0) => {
uninstall_make_depend(pkg);
addPkg(false, pkg);
}
Some(_) => {
err_unrec(format!("Couldn't install {}", pkg));

@ -0,0 +1,46 @@
use regex::bytes;
use toml_edit::{Document, value};
use std::io::{Read, Write, Error};
use std::fs::File;
pub fn remPkg(pkgs: &Vec<String>) {
let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap());
let mut database = std::fs::read_to_string(&file).expect("cant open database");
let mut updateDatabase = database;
for i in pkgs {
if updateDatabase.contains(i) {
let results = raur::search(&i);
for res in &results {
let databaseEntry = format!("{} = {{ name = \"{}\", version = \"{}\"}}\n",&res[0].name, &res[0].name, &res[0].version);
updateDatabase = format!("{}",updateDatabase.replace(&databaseEntry, ""));
}
}
}
let fileAsPath = File::create(std::path::Path::new(&file)).unwrap();
write!(&fileAsPath, "{}", updateDatabase);
}
pub fn addPkg(fromRepo: bool, pkg: &str) -> Result<(), Error> {
let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap());
let database = std::fs::read_to_string(&file).expect("cant open database");
let mut fileAsPath = File::create(std::path::Path::new(&file))?;
let mut dbParsed = database.parse::<Document>().expect("invalid Database");
if fromRepo == false {
let results = raur::search(&pkg);
for res in &results {
for r in res {
dbParsed[&r.name]["name"] = value(&r.name);
dbParsed[&r.name]["version"] = value(&r.version);
}
}
} else {
dbParsed[&pkg]["name"] = value(pkg);
dbParsed[&pkg]["version"] = value(pkg);
}
print!("{}",dbParsed);
fileAsPath.write_all(format!("{}",dbParsed).as_bytes()).unwrap();
Ok(())
}

@ -1,4 +1,4 @@
use crate::mods::strs::{err_rec, err_unrec, sec, succ};
use crate::mods::{strs::{err_rec, err_unrec, sec, succ}, database::remPkg};
use runas::Command;
use std::{fs, path::Path};
@ -15,10 +15,12 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => succ(format!(
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
)),
&pkgs.join(" ")));
remPkg(&pkgs);
},
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
};
@ -29,10 +31,12 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
.status()
.expect("Couldn't call pacman");
match result.code() {
Some(0) => succ(format!(
Some(0) => {
succ(format!(
"Succesfully uninstalled packages: {}",
&pkgs.join(" ")
)),
&pkgs.join(" ")));
remPkg(&pkgs);
},
Some(_) => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
None => err_rec(format!("Couldn't uninstall packages: {}", &pkgs.join(" "))),
};

@ -1,11 +1,16 @@
use crate::mods::strs::{err_unrec, inf, sec, succ};
use runas::Command;
use std::{env, fs};
use toml;
pub fn upgrade(noconfirm: bool) {
let homepath = std::env::var("HOME").unwrap();
let cachedir = format!("/{}/.cache/ame/", homepath);
let cache_exists = std::path::Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir();
let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap());
let database = std::fs::read_to_string(&file).expect("cant open database");
let mut dbParsed = database.parse::<toml::Value>().expect("invalid Database");
if cache_exists == false {
let cachecreate = fs::create_dir_all(&cachedir);
match cachecreate {
@ -40,7 +45,34 @@ pub fn upgrade(noconfirm: bool) {
};
}
for file in std::fs::read_dir(&cachedir).unwrap() {
println!("{:?}", dbParsed);
for entry in dbParsed.as_table() {
for (key, value) in &*entry {
//println!("{} / {}", key, value);
for (option, entry) in {
println!("{} / {}", option, entry);
}
//if key.contains("name") {
/* println!("{}",value);
let results = raur::search(format!("{}",entry["paru"]));
println!("{}",format!("{}",entry));
let mut test = value.to_string().replace("\"", "");
test = test.replace("version", "").replace("name","");
test = test.replace("=", "");
println!("{}",test.replace(" ",""));*/
//let results = raur::search(format!("{}",value));
//for res in results {
// println!("{}",&res[0].name);
//}
/*} else if key.contains("version") {
if value.as_integer() == lVersion {
println!("upgrading");
}
}*/
}
}
/*for file in std::fs::read_dir(&cachedir).unwrap() {
let dir = &file.unwrap().path();
let output = std::process::Command::new("git")
.arg("pull")
@ -82,5 +114,5 @@ pub fn upgrade(noconfirm: bool) {
None => err_unrec(format!("Couldn't install new AUR package version")),
};
}
}
}*/
}

Loading…
Cancel
Save