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,42 +18,54 @@ 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() {
inssort(noconfirm, pkgs); "-S" | "-Sn" | "ins" => {
} else if oper == "-R" || oper == "-Rn " || oper == "-Rsn" || oper == "-Rs" || oper == "rm" { inssort(noconfirm, pkgs);
uninstall(noconfirm, pkgs); }
} else if oper == "-Syu" || oper == "-Syun" || oper == "upg" { "-R" | "-Rn" | "-Rsn" | "-Rs" | "rm" => {
upgrade(noconfirm); uninstall(noconfirm, pkgs);
} else if oper == "-Sy" || oper == "upd" { }
update(); "-Syu" | "-Syun" |"upg" => {
} else if oper == "-Ss" || oper == "sea" { upgrade(noconfirm);
r_search(&args[2]); }
a_search(&args[2]); "-Sy" | "upd" => {
} else if oper == "-Sa" || oper == "aursea" { update();
a_search(&args[2]); }
} else if oper == "-Sr" || oper == "repsea" { "-Ss" | "sea" => {
r_search(&args[2]); r_search(&args[2]);
} else if oper == "-Cc" || oper == "clr" { a_search(&args[2]);
clearcache(); }
} else if oper == "-v" || oper == "-V" || oper == "ver" { "-Sa" | "aursea" => {
ver(); a_search(&args[2]);
} else if oper == "-h" || oper == "help" { }
help(); "-Sr" | "repsea" => {
} else { r_search(&args[2]);
let pass = Command::new("pacman") }
.args(env::args().skip(1)) "-Cc" | "clr" => {
.status() clearcache();
.expect("Something has gone wrong."); }
"-v" | "-V" | "ver" => {
ver();
}
"-h" | "help" => {
help()
}
_ => {
let pass = Command::new("pacman")
.args(env::args().skip(1))
.status()
.expect("Something has gone wrong.");
match pass.code() { match pass.code() {
Some(1) => { Some(1) => {
err_rec(format!("No such operation \"{}\"", args.join(" "))); err_rec(format!("No such operation \"{}\"", args.join(" ")));
inf(format!( inf(format!(
"Try running \"ame help\" for an overview of how to use ame" "Try running \"ame help\" for an overview of how to use ame"
)) ))
}
Some(_) => {}
None => err_unrec(format!("Something has gone terribly wrong.")),
} }
Some(_) => {}
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");
Ok(_) => { }
inf(format!("Database parsed")) false => {
let _cdar = std::fs::create_dir_all(format!("/{}/.local/ame/",homepath));
match _cdar {
Ok(_) => {
inf(format!("Created path for database (previously missing)"))
}
Err(_) => {
err_unrec(format!("Couldn't create path for database (~/.local/ame)"))
}
} }
Err(_) => { err_rec(String::from("Datbase wasn't found, creating new one"));
err_unrec(format!("Couldn't open database")) 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)); }
match _cdar { false => {
Ok(_) => { let _cdar = std::fs::create_dir_all(format!("/{}/.local/ame/",homepath));
inf(format!("Created cache directory (previously missing)")) match _cdar {
Ok(_) => {
inf(format!("Created path for database (previously missing)"))
}
Err(_) => {
err_unrec(format!("Couldn't create path for database (~/.local/ame)"))
}
} }
Err(_) => { err_rec(String::from("Datbase wasn't found, creating new one"));
err_unrec(format!("Couldn't create cache directory")) 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"))
}
} }
} }
err_rec(String::from("Database wasn't found, creating new one"));
let _dbfile = std::fs::File::create(&file);
let database = String::new();
} }
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