replaced the if else in main.rs with match, and fixed database

i18n
axtlos 3 years ago
parent d81d4e902a
commit 004556fff5

@ -1,20 +1,5 @@
mod mods; mod mods;
use mods::{ use mods::{clearcache::{clearcache}, clone::clone, help::help, inssort::inssort, install::install, search::{a_search, r_search}, strs::err_rec, strs::err_unrec, strs::inf, uninstall::{uninstall}, update::{update}, upgrade::{upgrade}, ver::ver, xargs::*};
clearcache::clearcache,
clone::clone,
help::help,
inssort::inssort,
install::install,
search::{a_search, r_search},
strs::err_rec,
strs::err_unrec,
strs::inf,
uninstall::uninstall,
update::update,
upgrade::upgrade,
ver::ver,
xargs::*,
};
use std::{env, process::exit, process::Command}; use std::{env, process::exit, process::Command};
fn main() { fn main() {
@ -33,28 +18,39 @@ fn main() {
// at some point weve GOT TO rework this into a `match` statement // at some point weve GOT TO rework this into a `match` statement
if oper == "-S" || oper == "-Sn" || oper == "ins" { match oper.as_str() {
"-S" | "-Sn" | "ins" => {
inssort(noconfirm, pkgs); inssort(noconfirm, pkgs);
} else if oper == "-R" || oper == "-Rn " || oper == "-Rsn" || oper == "-Rs" || oper == "rm" { }
"-R" | "-Rn" | "-Rsn" | "-Rs" | "rm" => {
uninstall(noconfirm, pkgs); uninstall(noconfirm, pkgs);
} else if oper == "-Syu" || oper == "-Syun" || oper == "upg" { }
"-Syu" | "-Syun" |"upg" => {
upgrade(noconfirm); upgrade(noconfirm);
} else if oper == "-Sy" || oper == "upd" { }
"-Sy" | "upd" => {
update(); update();
} else if oper == "-Ss" || oper == "sea" { }
"-Ss" | "sea" => {
r_search(&args[2]); r_search(&args[2]);
a_search(&args[2]); a_search(&args[2]);
} else if oper == "-Sa" || oper == "aursea" { }
"-Sa" | "aursea" => {
a_search(&args[2]); a_search(&args[2]);
} else if oper == "-Sr" || oper == "repsea" { }
"-Sr" | "repsea" => {
r_search(&args[2]); r_search(&args[2]);
} else if oper == "-Cc" || oper == "clr" { }
"-Cc" | "clr" => {
clearcache(); clearcache();
} else if oper == "-v" || oper == "-V" || oper == "ver" { }
"-v" | "-V" | "ver" => {
ver(); ver();
} else if oper == "-h" || oper == "help" { }
help(); "-h" | "help" => {
} else { help()
}
_ => {
let pass = Command::new("pacman") let pass = Command::new("pacman")
.args(env::args().skip(1)) .args(env::args().skip(1))
.status() .status()
@ -71,4 +67,5 @@ fn main() {
None => err_unrec(format!("Something has gone terribly wrong.")), None => err_unrec(format!("Something has gone terribly wrong.")),
} }
} }
}
} }

@ -5,21 +5,34 @@ use toml_edit::{value, Document};
use crate::mods::strs::{err_rec}; use crate::mods::strs::{err_rec};
pub fn rem_pkg(pkgs: &Vec<String>) { pub fn rem_pkg(pkgs: &Vec<String>) {
let homepath = std::env::var("HOME").unwrap();
let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap()); let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap());
let database = String::new(); let mut database = String::new();
if std::path::Path::new(&file).exists() { match std::path::Path::new(&file).exists() {
let _db = std::fs::read_to_string(&file); true => {
match _db { database = std::fs::read_to_string(&file).expect("Can't Open Database");
}
false => {
let _cdar = std::fs::create_dir_all(format!("/{}/.local/ame/",homepath));
match _cdar {
Ok(_) => { Ok(_) => {
inf(format!("Database parsed")) inf(format!("Created path for database (previously missing)"))
} }
Err(_) => { Err(_) => {
err_unrec(format!("Couldn't open database")) err_unrec(format!("Couldn't create path for database (~/.local/ame)"))
}
}
err_rec(String::from("Datbase wasn't found, creating new one"));
let _dbfile = std::fs::File::create(&file);
match _dbfile {
Ok(_) => {
inf(format!("Created empty database (previously missing)"))
}
Err(_) => {
err_unrec(format!("Couldn't create database"))
}
} }
} }
} else {
err_rec(String::from("Database wasn't found, creating new one"));
let _dbfile = File::create(&file);
} }
let mut update_database = database; let mut update_database = database;
@ -46,26 +59,35 @@ pub fn rem_pkg(pkgs: &Vec<String>) {
pub fn add_pkg(from_repo: bool, pkg: &str) -> Result<(), Error> { pub fn add_pkg(from_repo: bool, pkg: &str) -> Result<(), Error> {
let homepath = std::env::var("HOME").unwrap(); let homepath = std::env::var("HOME").unwrap();
let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap()); let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap());
let database = String::new(); let mut database = String::new();
if std::path::Path::new(&file).exists() { match std::path::Path::new(&file).exists() {
let database = std::fs::read_to_string(&file).expect("Can't Open Database"); true => {
} else { database = std::fs::read_to_string(&file).expect("Can't Open Database");
let _cdar = std::fs::create_dir_all(format!("/{}/.local/ame/", homepath)); }
false => {
let _cdar = std::fs::create_dir_all(format!("/{}/.local/ame/",homepath));
match _cdar { match _cdar {
Ok(_) => { Ok(_) => {
inf(format!("Created cache directory (previously missing)")) inf(format!("Created path for database (previously missing)"))
} }
Err(_) => { Err(_) => {
err_unrec(format!("Couldn't create cache directory")) err_unrec(format!("Couldn't create path for database (~/.local/ame)"))
} }
} }
err_rec(String::from("Database wasn't found, creating new one")); err_rec(String::from("Datbase wasn't found, creating new one"));
let _dbfile = std::fs::File::create(&file); let _dbfile = std::fs::File::create(&file);
let database = String::new(); match _dbfile {
Ok(_) => {
inf(format!("Created empty database (previously missing)"))
}
Err(_) => {
err_unrec(format!("Couldn't create database"))
}
}
}
} }
let mut db_parsed = database.parse::<Document>().expect("Invalid Database"); let mut db_parsed = database.parse::<Document>().expect("Invalid Database");
let mut file_as_path = File::create(std::path::Path::new(&file))?; let mut file_as_path = File::create(std::path::Path::new(&file))?;
if from_repo == false { if from_repo == false {
let results = raur::search(&pkg); let results = raur::search(&pkg);
for res in &results { for res in &results {

Loading…
Cancel
Save