add basic comments

i18n
Amy 3 years ago
parent 6a212e2bc8
commit 5d73021e3a
No known key found for this signature in database
GPG Key ID: 6672E6DD65BEA50B

@ -5,7 +5,7 @@ use nix::unistd::Uid;
fn main() { fn main() {
if Uid::effective().is_root() { if Uid::effective().is_root() { // check if user runs ame as root
err_unrec(format!("Do not run ame as root! this can cause serious damage to your system!")); err_unrec(format!("Do not run ame as root! this can cause serious damage to your system!"));
} }
@ -22,51 +22,51 @@ fn main() {
argssort(&mut pkgs); argssort(&mut pkgs);
match oper.as_str() { match oper.as_str() { // match oper
"-S" | "-Sn" | "ins" => { "-S" | "-Sn" | "ins" => {
inssort(noconfirm, false, pkgs); inssort(noconfirm, false, pkgs); // install
} }
"-Sl" | "-Sln" | "insl" => { "-Sl" | "-Sln" | "insl" => {
inssort_from_file(noconfirm, false, &pkgs[0]); inssort_from_file(noconfirm, false, &pkgs[0]); // install from file
} }
"-R" | "-Rn" | "rm" => { "-R" | "-Rn" | "rm" => {
uninstall(noconfirm, pkgs); uninstall(noconfirm, pkgs); // uninstall
} }
"-Rs" | "-Rsn" | "purge" => { "-Rs" | "-Rsn" | "purge" => {
purge(noconfirm, pkgs) purge(noconfirm, pkgs); // purge
} }
"-Rl" | "-Rln" | "rml" => { "-Rl" | "-Rln" | "rml" => {
uninstall_from_file(noconfirm, &pkgs[0]); uninstall_from_file(noconfirm, &pkgs[0]); // uninstall from file
} }
"-Rsl" | "-Rsln" | "purgel" => { "-Rsl" | "-Rsln" | "purgel" => {
purge_from_file(noconfirm, &pkgs[0]); purge_from_file(noconfirm, &pkgs[0]); // purge from file
} }
"-Syu" | "-Syun" |"upg" => { "-Syu" | "-Syun" |"upg" => {
upgrade(noconfirm); upgrade(noconfirm); // upgrade
} }
"-Sy" | "upd" => { "-Sy" | "upd" => {
update(); update(); // update
} }
"-Ss" | "sea" => { "-Ss" | "sea" => {
r_search(&args[2]); r_search(&args[2]); // search for packages in the repository
a_search(&args[2]); a_search(&args[2]); // search for packages in the aur
} }
"-Sa" | "aursea" => { "-Sa" | "aursea" => {
a_search(&args[2]); a_search(&args[2]); // search for packages in the aur
} }
"-Sr" | "repsea" => { "-Sr" | "repsea" => {
r_search(&args[2]); r_search(&args[2]); // search for packages in the repository
} }
"-Cc" | "clr" => { "-Cc" | "clr" => {
clearcache(); clearcache(); // clear cache
} }
"-v" | "-V" | "ver" => { "-v" | "-V" | "ver" => {
ver(); ver(); // version
} }
"-h" | "help" => { "-h" | "help" => {
help() help(); // help
} }
_ => { _ => { // if oper is not valid it either passes the args to pacman or prints an error
let pass = Command::new("pacman") let pass = Command::new("pacman")
.args(env::args().skip(1)) .args(env::args().skip(1))
.status() .status()

@ -1,7 +1,7 @@
use crate::mods::strs::err_rec; use crate::mods::strs::err_rec;
use std::fs; use std::fs;
pub fn clearcache() { pub fn clearcache() { // delete all files in cache
let path = format!("{}/.cache/ame/", std::env::var("HOME").unwrap()); let path = format!("{}/.cache/ame/", std::env::var("HOME").unwrap());
err_rec(format!("Clearing cache")); err_rec(format!("Clearing cache"));

@ -6,7 +6,7 @@ use git2::Repository;
use moins::Moins; use moins::Moins;
use std::{env, fs, path::Path, process::Command}; use std::{env, fs, path::Path, process::Command};
fn uninstall_make_depend(pkg: &str) { fn uninstall_make_depend(pkg: &str) { // uninstall make depends of a package
let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone(); let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone();
let explicit_packages = Command::new("pacman") let explicit_packages = Command::new("pacman")
@ -50,7 +50,7 @@ fn uninstall_make_depend(pkg: &str) {
succ(format!("Succesfully installed {}", pkg)); succ(format!("Succesfully installed {}", pkg));
} }
pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { pub fn clone(noconfirm: bool, as_dep: bool, pkg: &str) { // clone a package from aur
let cachedir = format!("{}/.cache/ame", env::var("HOME").unwrap()); let cachedir = format!("{}/.cache/ame", env::var("HOME").unwrap());
let path = Path::new(&cachedir); let path = Path::new(&cachedir);
let pkgdir = format!("{}/{}", &cachedir, &pkg); let pkgdir = format!("{}/{}", &cachedir, &pkg);

@ -3,7 +3,7 @@ use std::{fs, io::{Error, Write}, env, path};
use toml_edit::{value, Document}; use toml_edit::{value, Document};
use crate::mods::strs::{err_rec}; use crate::mods::strs::{err_rec};
pub fn get_value(pkg: &str, sear_value: &str) -> String { pub fn get_value(pkg: &str, sear_value: &str) -> String { // Get specific value from database
let homepath = env::var("HOME").unwrap(); let homepath = env::var("HOME").unwrap();
let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap());
let mut database = String::new(); let mut database = String::new();
@ -71,7 +71,7 @@ pub fn get_value(pkg: &str, sear_value: &str) -> String {
return return_val; return return_val;
} }
pub fn rem_pkg(pkgs: &Vec<String>) { pub fn rem_pkg(pkgs: &Vec<String>) { // Remove packages from database
let homepath = env::var("HOME").unwrap(); let homepath = env::var("HOME").unwrap();
let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap());
let mut database = String::new(); let mut database = String::new();
@ -123,7 +123,7 @@ 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> { // Add package to database
let homepath = env::var("HOME").unwrap(); let homepath = env::var("HOME").unwrap();
let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap());
let mut database = String::new(); let mut database = String::new();

@ -1,6 +1,6 @@
use crate::mods::strs::{err_rec, inf}; use crate::mods::strs::{err_rec, inf};
pub fn help() { pub fn help() { // print help message
println!(""); println!("");
inf(format!("Usage:")); inf(format!("Usage:"));
println!( println!(

@ -2,7 +2,7 @@ use crate::{clone, err_unrec, install, mods::strs::sec};
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use regex::Regex; use regex::Regex;
pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) { // TODO: understand what the fuck is actually going on here
let mut repo = vec![]; let mut repo = vec![];
let mut aur = vec![]; let mut aur = vec![];
let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap(); let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap();
@ -91,7 +91,7 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec<String>) {
} }
} }
pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { pub fn inssort_from_file(noconfirm: bool, as_dep: bool, file: &str) { // same thing as above but with a list of packages from a file
let mut pkgs: Vec<String> = Vec::new(); let mut pkgs: Vec<String> = Vec::new();
let mut contents = String::new(); let mut contents = String::new();
contents = std::fs::read_to_string(&file).expect("Couldn't read file"); contents = std::fs::read_to_string(&file).expect("Couldn't read file");

@ -2,7 +2,7 @@ use crate::mods::strs::{err_unrec, succ};
use runas::Command; use runas::Command;
use std::fs::File; use std::fs::File;
pub fn install(noconfirm: bool, as_dep: bool, pkg: &str) { pub fn install(noconfirm: bool, as_dep: bool, pkg: &str) { // install a package
let pkgs: Vec<&str> = pkg.split(" ").collect(); let pkgs: Vec<&str> = pkg.split(" ").collect();
if as_dep == false { if as_dep == false {
if noconfirm == true { if noconfirm == true {

@ -5,7 +5,7 @@ use crate::mods::{
use runas::Command; use runas::Command;
use std::{fs, path::Path}; use std::{fs, path::Path};
pub fn purge(noconfirm: bool, pkgs: Vec<String>) { pub fn purge(noconfirm: bool, pkgs: Vec<String>) { // purge packages
sec(format!( sec(format!(
"Attempting to uninstall packages: {}", "Attempting to uninstall packages: {}",
&pkgs.join(" ") &pkgs.join(" ")
@ -60,7 +60,7 @@ pub fn purge(noconfirm: bool, pkgs: Vec<String>) {
} }
pub fn purge_from_file(noconfirm: bool, file: &str) { pub fn purge_from_file(noconfirm: bool, file: &str) { // purge packages from list of packages
let mut pkgs: Vec<String> = Vec::new(); let mut pkgs: Vec<String> = Vec::new();
let mut contents = String::new(); let mut contents = String::new();
contents = std::fs::read_to_string(&file).expect("Couldn't read file"); contents = std::fs::read_to_string(&file).expect("Couldn't read file");

@ -2,7 +2,7 @@ use crate::mods::strs::{err_rec, err_unrec, succ};
use ansi_term::Colour; use ansi_term::Colour;
use std::{ops::Deref, process::Command}; use std::{ops::Deref, process::Command};
pub fn a_search(pkg: &str) { pub fn a_search(pkg: &str) { // search for a package in the AUR
let results = raur::search(&pkg); let results = raur::search(&pkg);
for r in &results { for r in &results {
@ -21,7 +21,7 @@ pub fn a_search(pkg: &str) {
} }
} }
pub fn r_search(pkg: &str) { pub fn r_search(pkg: &str) { // search for a package in the repositories
let result = Command::new("pacman") let result = Command::new("pacman")
.arg("-Ss") .arg("-Ss")
.arg(&pkg) .arg(&pkg)

@ -2,7 +2,7 @@ use ansi_term::Colour;
use std::{env, io, io::Write, process, string}; use std::{env, io, io::Write, process, string};
use uwuizer::*; use uwuizer::*;
pub fn inf(a: string::String) { pub fn inf(a: string::String) { // info
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!( println!(
"{} {}", "{} {}",
@ -14,7 +14,7 @@ pub fn inf(a: string::String) {
} }
} }
pub fn sec(a: string::String) { pub fn sec(a: string::String) {
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!( println!(
"{} {}", "{} {}",
@ -30,7 +30,7 @@ pub fn sec(a: string::String) {
} }
} }
pub fn succ(a: string::String) { pub fn succ(a: string::String) { // success
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!( println!(
"{} {}", "{} {}",
@ -46,7 +46,7 @@ pub fn succ(a: string::String) {
} }
} }
pub fn prompt(a: string::String) -> bool { pub fn prompt(a: string::String) -> bool { // prompt
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
print!( print!(
"{} {} {}", "{} {} {}",
@ -80,7 +80,7 @@ pub fn prompt(a: string::String) -> bool {
} }
} }
pub fn err_unrec(a: string::String) { pub fn err_unrec(a: string::String) { // unrecoverable error
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!( println!(
"{} {} {}", "{} {} {}",
@ -100,7 +100,7 @@ pub fn err_unrec(a: string::String) {
} }
} }
pub fn err_rec(a: string::String) { pub fn err_rec(a: string::String) { // recoverable error
if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" { if env::var("AME_UWU").unwrap_or("n/a".to_string()) == "YES" {
println!( println!(
"{} {}", "{} {}",

@ -5,7 +5,7 @@ use crate::mods::{
use runas::Command; use runas::Command;
use std::{fs, path::Path}; use std::{fs, path::Path};
pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) { pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) { // uninstall a package
sec(format!( sec(format!(
"Attempting to uninstall packages: {}", "Attempting to uninstall packages: {}",
&pkgs.join(" ") &pkgs.join(" ")
@ -59,7 +59,7 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec<String>) {
} }
} }
pub fn uninstall_from_file(noconfirm: bool, file: &str) { pub fn uninstall_from_file(noconfirm: bool, file: &str) { // uninstall a package from a list of packages
let mut pkgs: Vec<String> = Vec::new(); let mut pkgs: Vec<String> = Vec::new();
let mut contents = String::new(); let mut contents = String::new();
contents = std::fs::read_to_string(&file).expect("Couldn't read file"); contents = std::fs::read_to_string(&file).expect("Couldn't read file");

@ -1,7 +1,7 @@
use crate::mods::strs::{err_unrec, sec, succ}; use crate::mods::strs::{err_unrec, sec, succ};
use runas::Command; use runas::Command;
pub fn update() { pub fn update() { // update the repositories
sec(format!("Syncing package repos")); sec(format!("Syncing package repos"));
let result = Command::new("pacman") let result = Command::new("pacman")

@ -6,7 +6,7 @@ use runas::Command;
use std::{env, fs, path::Path}; use std::{env, fs, path::Path};
use toml; use toml;
fn uninstall_make_depend(pkg: &str) { fn uninstall_make_depend(pkg: &str) { // uninstall make depends installed by ame itself
let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone(); let make_depends = raur::info(&[&pkg]).unwrap()[0].make_depends.clone();
if make_depends.len() != 0 { if make_depends.len() != 0 {
@ -23,7 +23,7 @@ fn uninstall_make_depend(pkg: &str) {
succ(format!("Succesfully upgraded {}", pkg)); succ(format!("Succesfully upgraded {}", pkg));
} }
pub fn upgrade(noconfirm: bool) { pub fn upgrade(noconfirm: bool) { // upgrade all packages
let homepath = env::var("HOME").unwrap(); let homepath = env::var("HOME").unwrap();
let cachedir = format!("/{}/.cache/ame/", homepath); let cachedir = format!("/{}/.cache/ame/", homepath);
let cache_exists = Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir(); let cache_exists = Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir();

@ -2,7 +2,7 @@ use crate::inf;
use ansi_term::Colour; use ansi_term::Colour;
use clap::{self, crate_version}; use clap::{self, crate_version};
pub fn ver() { pub fn ver() { // print version and contributors
println!(""); println!("");
inf(format!("ame - {}",crate_version!())); inf(format!("ame - {}",crate_version!()));
println!(""); println!("");

@ -1,4 +1,4 @@
pub fn noconf(args: &Vec<String>) -> bool { pub fn noconf(args: &Vec<String>) -> bool { // noconfirm if user passed --noconfirm or added n to the end of the arg
if args.contains(&"--noconfirm".to_string()) || args[1].ends_with(&"n".to_string()) { if args.contains(&"--noconfirm".to_string()) || args[1].ends_with(&"n".to_string()) {
true true
} else { } else {
@ -6,7 +6,7 @@ pub fn noconf(args: &Vec<String>) -> bool {
} }
} }
pub fn argssort(args: &mut Vec<String>) -> &Vec<String> { pub fn argssort(args: &mut Vec<String>) -> &Vec<String> { // sort the args
if args.contains(&"--noconfirm".to_string()) { if args.contains(&"--noconfirm".to_string()) {
args.retain(|x| x != &"--noconfirm".to_string()); args.retain(|x| x != &"--noconfirm".to_string());
args args

Loading…
Cancel
Save