diff --git a/Cargo.toml b/Cargo.toml index c77911a..53f2e53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ame" -version = "2.4.1" +version = "2.4.2" authors = [ "jnats ", "axtlos " ] edition = "2018" description = "a fast and efficient aur helper." @@ -18,4 +18,5 @@ regex = "*" toml_edit = "0.5.0" toml = "*" bytes = "*" -nix = "*" \ No newline at end of file +nix = "*" +clap = "*" \ No newline at end of file diff --git a/src/mods/clone.rs b/src/mods/clone.rs index a10685f..18d9b50 100644 --- a/src/mods/clone.rs +++ b/src/mods/clone.rs @@ -52,7 +52,7 @@ fn uninstall_make_depend(pkg: &str) { } pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { - let cachedir = format!("{}/.cache/ame", std::env::var("HOME").unwrap()); + let cachedir = format!("{}/.cache/ame", env::var("HOME").unwrap()); let path = Path::new(&cachedir); let pkgdir = format!("{}/{}", &cachedir, &pkg); let package = raur::info(&[pkg]).unwrap(); diff --git a/src/mods/database.rs b/src/mods/database.rs index 78de816..dd43afa 100644 --- a/src/mods/database.rs +++ b/src/mods/database.rs @@ -1,19 +1,18 @@ use crate::{err_unrec, inf}; -use std::fs::File; -use std::io::{Error, Write}; +use std::{fs, io::{Error, Write}, env, path}; use toml_edit::{value, Document}; use crate::mods::strs::{err_rec}; pub fn get_value(pkg: &str, sear_value: &str) -> String { - let homepath = std::env::var("HOME").unwrap(); - let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap()); + let homepath = env::var("HOME").unwrap(); + let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let mut database = String::new(); - match std::path::Path::new(&file).exists() { + match path::Path::new(&file).exists() { true => { - database = std::fs::read_to_string(&file).expect("Can't Open Database"); + database = fs::read_to_string(&file).expect("Can't Open Database"); } false => { - let _cdar = std::fs::create_dir_all(format!("/{}/.local/ame/",homepath)); + let _cdar = fs::create_dir_all(format!("/{}/.local/ame/",homepath)); match _cdar { Ok(_) => { inf(format!("Created path for database (previously missing)")) @@ -23,7 +22,7 @@ pub fn get_value(pkg: &str, sear_value: &str) -> String { } } err_rec(String::from("Datbase wasn't found, creating new one")); - let _dbfile = std::fs::File::create(&file); + let _dbfile = fs::File::create(&file); match _dbfile { Ok(_) => { inf(format!("Created empty database (previously missing)")) @@ -73,15 +72,15 @@ pub fn get_value(pkg: &str, sear_value: &str) -> String { } pub fn rem_pkg(pkgs: &Vec) { - let homepath = std::env::var("HOME").unwrap(); - let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap()); + let homepath = env::var("HOME").unwrap(); + let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let mut database = String::new(); - match std::path::Path::new(&file).exists() { + match path::Path::new(&file).exists() { true => { - database = std::fs::read_to_string(&file).expect("Can't Open Database"); + database = fs::read_to_string(&file).expect("Can't Open Database"); } false => { - let _cdar = std::fs::create_dir_all(format!("/{}/.local/ame/",homepath)); + let _cdar = fs::create_dir_all(format!("/{}/.local/ame/",homepath)); match _cdar { Ok(_) => { inf(format!("Created path for database (previously missing)")) @@ -91,7 +90,7 @@ pub fn rem_pkg(pkgs: &Vec) { } } err_rec(String::from("Datbase wasn't found, creating new one")); - let _dbfile = std::fs::File::create(&file); + let _dbfile = fs::File::create(&file); match _dbfile { Ok(_) => { inf(format!("Created empty database (previously missing)")) @@ -116,7 +115,7 @@ pub fn rem_pkg(pkgs: &Vec) { } } } - let file_as_path = File::create(std::path::Path::new(&file)).unwrap(); + let file_as_path = fs::File::create(path::Path::new(&file)).unwrap(); let db_update_res = write!(&file_as_path, "{}", update_database); match db_update_res { Ok(_) => inf(format!("Database update successful")), @@ -125,15 +124,15 @@ pub fn rem_pkg(pkgs: &Vec) { } pub fn add_pkg(from_repo: bool, pkg: &str) -> Result<(), Error> { - let homepath = std::env::var("HOME").unwrap(); - let file = format!("{}/.local/ame/aurPkgs.db", std::env::var("HOME").unwrap()); + let homepath = env::var("HOME").unwrap(); + let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let mut database = String::new(); - match std::path::Path::new(&file).exists() { + match path::Path::new(&file).exists() { true => { - database = std::fs::read_to_string(&file).expect("Can't Open Database"); + database = fs::read_to_string(&file).expect("Can't Open Database"); } false => { - let _cdar = std::fs::create_dir_all(format!("/{}/.local/ame/",homepath)); + let _cdar = fs::create_dir_all(format!("/{}/.local/ame/",homepath)); match _cdar { Ok(_) => { inf(format!("Created path for database (previously missing)")) @@ -143,7 +142,7 @@ pub fn add_pkg(from_repo: bool, pkg: &str) -> Result<(), Error> { } } err_rec(String::from("Datbase wasn't found, creating new one")); - let _dbfile = std::fs::File::create(&file); + let _dbfile = fs::File::create(&file); match _dbfile { Ok(_) => { inf(format!("Created empty database (previously missing)")) @@ -155,14 +154,12 @@ pub fn add_pkg(from_repo: bool, pkg: &str) -> Result<(), Error> { } } let mut db_parsed = database.parse::().expect("Invalid Database"); - let mut file_as_path = File::create(std::path::Path::new(&file))?; + let mut file_as_path = fs::File::create(path::Path::new(&file))?; if from_repo == false { let results = raur::search(&pkg); for res in &results { - //for r in res { - db_parsed[&res[0].name]["name"] = value(&res[0].name); - db_parsed[&res[0].name]["version"] = value(&res[0].version); - //} + db_parsed[&res[0].name]["name"] = value(&res[0].name); + db_parsed[&res[0].name]["version"] = value(&res[0].version); } } else { db_parsed[&pkg]["name"] = value(pkg); diff --git a/src/mods/inssort.rs b/src/mods/inssort.rs index c9eceab..66b03c7 100644 --- a/src/mods/inssort.rs +++ b/src/mods/inssort.rs @@ -1,11 +1,12 @@ use crate::{clone, err_unrec, install, mods::strs::sec}; use std::process::{Command, Stdio}; +use regex::Regex; pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec) { let mut repo = vec![]; let mut aur = vec![]; - let re = regex::Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap(); - let reg = regex::Regex::new(r"((?:>=|<=)\S+$)").unwrap(); + let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap(); + let reg = Regex::new(r"((?:>=|<=)\S+$)").unwrap(); for pkg in pkgs { let caps = re.captures(&pkg); match caps { diff --git a/src/mods/strs.rs b/src/mods/strs.rs index d37e642..24aa30a 100644 --- a/src/mods/strs.rs +++ b/src/mods/strs.rs @@ -1,8 +1,8 @@ use ansi_term::Colour; -use std::{env, io, io::Write, process}; +use std::{env, io, io::Write, process, string}; use uwuizer::*; -pub fn inf(a: std::string::String) { +pub fn inf(a: string::String) { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { println!( "{} {}", @@ -14,7 +14,7 @@ pub fn inf(a: std::string::String) { } } -pub fn sec(a: std::string::String) { +pub fn sec(a: string::String) { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { println!( "{} {}", @@ -30,7 +30,7 @@ pub fn sec(a: std::string::String) { } } -pub fn succ(a: std::string::String) { +pub fn succ(a: string::String) { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { println!( "{} {}", @@ -46,7 +46,7 @@ pub fn succ(a: std::string::String) { } } -pub fn prompt(a: std::string::String) -> bool { +pub fn prompt(a: string::String) -> bool { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { print!( "{} {} {}", @@ -80,7 +80,7 @@ pub fn prompt(a: std::string::String) -> bool { } } -pub fn err_unrec(a: std::string::String) { +pub fn err_unrec(a: string::String) { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { println!( "{} {} {}", @@ -100,7 +100,7 @@ pub fn err_unrec(a: std::string::String) { } } -pub fn err_rec(a: std::string::String) { +pub fn err_rec(a: string::String) { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { println!( "{} {}", diff --git a/src/mods/upgrade.rs b/src/mods/upgrade.rs index b339844..c88e711 100644 --- a/src/mods/upgrade.rs +++ b/src/mods/upgrade.rs @@ -24,13 +24,13 @@ fn uninstall_make_depend(pkg: &str) { } pub fn upgrade(noconfirm: bool) { - let homepath = std::env::var("HOME").unwrap(); + let homepath = 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 cache_exists = Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir(); + let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let database = String::new(); - if std::path::Path::new(&file).exists() { - let _db = std::fs::read_to_string(&file).expect("Can't Open Database"); + if Path::new(&file).exists() { + let _db = fs::read_to_string(&file).expect("Can't Open Database"); } else { let _cdar = fs::create_dir_all(format!("/{}/.local/ame/", homepath)); match _cdar { @@ -42,7 +42,7 @@ pub fn upgrade(noconfirm: bool) { } } err_rec(String::from("Database wasn't found, creating new one")); - let _dbfile = std::fs::File::create(&file); + let _dbfile = fs::File::create(&file); let _db = String::new(); } let db_parsed = database.parse::().expect("Invalid Database"); @@ -87,7 +87,7 @@ pub fn upgrade(noconfirm: bool) { let version = get_value(&key, "version"); if res[0].version.contains(&version) { let keydir = format!("{}{}", &cachedir, &key); - if std::path::Path::new(&keydir).is_dir() { + if Path::new(&keydir).is_dir() { let cd_result = env::set_current_dir(&keydir); match cd_result { Ok(_) => inf(format!("Entered package directory")), diff --git a/src/mods/ver.rs b/src/mods/ver.rs index 7851921..ba56bdf 100644 --- a/src/mods/ver.rs +++ b/src/mods/ver.rs @@ -1,9 +1,10 @@ use crate::inf; use ansi_term::Colour; +use clap::{self, crate_version}; pub fn ver() { println!(""); - inf(format!("ame - v2.4.1")); + inf(format!("ame - {}",crate_version!())); println!(""); inf(format!("Contributors:")); println!("- axtlos ");