From 5d73021e3a279a95716f0554c8d19bac5d3da125 Mon Sep 17 00:00:00 2001 From: Amy Date: Fri, 12 Nov 2021 20:56:07 +0100 Subject: [PATCH] add basic comments --- src/main.rs | 36 ++++++++++++++++++------------------ src/mods/clearcache.rs | 2 +- src/mods/clone.rs | 4 ++-- src/mods/database.rs | 6 +++--- src/mods/help.rs | 2 +- src/mods/inssort.rs | 4 ++-- src/mods/install.rs | 2 +- src/mods/purge.rs | 4 ++-- src/mods/search.rs | 4 ++-- src/mods/strs.rs | 12 ++++++------ src/mods/uninstall.rs | 4 ++-- src/mods/update.rs | 2 +- src/mods/upgrade.rs | 4 ++-- src/mods/ver.rs | 2 +- src/mods/xargs.rs | 4 ++-- 15 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8261046..108c519 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use nix::unistd::Uid; 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!")); } @@ -22,51 +22,51 @@ fn main() { argssort(&mut pkgs); - match oper.as_str() { + match oper.as_str() { // match oper "-S" | "-Sn" | "ins" => { - inssort(noconfirm, false, pkgs); + inssort(noconfirm, false, pkgs); // install } "-Sl" | "-Sln" | "insl" => { - inssort_from_file(noconfirm, false, &pkgs[0]); + inssort_from_file(noconfirm, false, &pkgs[0]); // install from file } "-R" | "-Rn" | "rm" => { - uninstall(noconfirm, pkgs); + uninstall(noconfirm, pkgs); // uninstall } "-Rs" | "-Rsn" | "purge" => { - purge(noconfirm, pkgs) + purge(noconfirm, pkgs); // purge } "-Rl" | "-Rln" | "rml" => { - uninstall_from_file(noconfirm, &pkgs[0]); + uninstall_from_file(noconfirm, &pkgs[0]); // uninstall from file } "-Rsl" | "-Rsln" | "purgel" => { - purge_from_file(noconfirm, &pkgs[0]); + purge_from_file(noconfirm, &pkgs[0]); // purge from file } "-Syu" | "-Syun" |"upg" => { - upgrade(noconfirm); + upgrade(noconfirm); // upgrade } "-Sy" | "upd" => { - update(); + update(); // update } "-Ss" | "sea" => { - r_search(&args[2]); - a_search(&args[2]); + r_search(&args[2]); // search for packages in the repository + a_search(&args[2]); // search for packages in the aur } "-Sa" | "aursea" => { - a_search(&args[2]); + a_search(&args[2]); // search for packages in the aur } "-Sr" | "repsea" => { - r_search(&args[2]); + r_search(&args[2]); // search for packages in the repository } "-Cc" | "clr" => { - clearcache(); + clearcache(); // clear cache } "-v" | "-V" | "ver" => { - ver(); + ver(); // version } "-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") .args(env::args().skip(1)) .status() diff --git a/src/mods/clearcache.rs b/src/mods/clearcache.rs index 921c4bd..e850603 100644 --- a/src/mods/clearcache.rs +++ b/src/mods/clearcache.rs @@ -1,7 +1,7 @@ use crate::mods::strs::err_rec; use std::fs; -pub fn clearcache() { +pub fn clearcache() { // delete all files in cache let path = format!("{}/.cache/ame/", std::env::var("HOME").unwrap()); err_rec(format!("Clearing cache")); diff --git a/src/mods/clone.rs b/src/mods/clone.rs index 63bd178..6cb6ba4 100644 --- a/src/mods/clone.rs +++ b/src/mods/clone.rs @@ -6,7 +6,7 @@ use git2::Repository; use moins::Moins; 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 explicit_packages = Command::new("pacman") @@ -50,7 +50,7 @@ fn uninstall_make_depend(pkg: &str) { 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 path = Path::new(&cachedir); let pkgdir = format!("{}/{}", &cachedir, &pkg); diff --git a/src/mods/database.rs b/src/mods/database.rs index e460f3e..f2bbe92 100644 --- a/src/mods/database.rs +++ b/src/mods/database.rs @@ -3,7 +3,7 @@ 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 { +pub fn get_value(pkg: &str, sear_value: &str) -> String { // Get specific value from database let homepath = env::var("HOME").unwrap(); let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let mut database = String::new(); @@ -71,7 +71,7 @@ pub fn get_value(pkg: &str, sear_value: &str) -> String { return return_val; } -pub fn rem_pkg(pkgs: &Vec) { +pub fn rem_pkg(pkgs: &Vec) { // Remove packages from database let homepath = env::var("HOME").unwrap(); let file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let mut database = String::new(); @@ -123,7 +123,7 @@ pub fn rem_pkg(pkgs: &Vec) { } } -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 file = format!("{}/.local/ame/aurPkgs.db", env::var("HOME").unwrap()); let mut database = String::new(); diff --git a/src/mods/help.rs b/src/mods/help.rs index d3feaf2..acba2ce 100644 --- a/src/mods/help.rs +++ b/src/mods/help.rs @@ -1,6 +1,6 @@ use crate::mods::strs::{err_rec, inf}; -pub fn help() { +pub fn help() { // print help message println!(""); inf(format!("Usage:")); println!( diff --git a/src/mods/inssort.rs b/src/mods/inssort.rs index 2315b56..303b75a 100644 --- a/src/mods/inssort.rs +++ b/src/mods/inssort.rs @@ -2,7 +2,7 @@ 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) { +pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec) { // TODO: understand what the fuck is actually going on here let mut repo = vec![]; let mut aur = vec![]; let re = Regex::new(r"(\S+)((?:>=|<=)\S+$)").unwrap(); @@ -91,7 +91,7 @@ pub fn inssort(noconfirm: bool, as_dep: bool, pkgs: Vec) { } } -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 = Vec::new(); let mut contents = String::new(); contents = std::fs::read_to_string(&file).expect("Couldn't read file"); diff --git a/src/mods/install.rs b/src/mods/install.rs index ac2bdfb..a2c9b0a 100644 --- a/src/mods/install.rs +++ b/src/mods/install.rs @@ -2,7 +2,7 @@ use crate::mods::strs::{err_unrec, succ}; use runas::Command; 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(); if as_dep == false { if noconfirm == true { diff --git a/src/mods/purge.rs b/src/mods/purge.rs index ac3b956..d5b0028 100644 --- a/src/mods/purge.rs +++ b/src/mods/purge.rs @@ -5,7 +5,7 @@ use crate::mods::{ use runas::Command; use std::{fs, path::Path}; -pub fn purge(noconfirm: bool, pkgs: Vec) { +pub fn purge(noconfirm: bool, pkgs: Vec) { // purge packages sec(format!( "Attempting to uninstall packages: {}", &pkgs.join(" ") @@ -60,7 +60,7 @@ pub fn purge(noconfirm: bool, pkgs: Vec) { } -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 = Vec::new(); let mut contents = String::new(); contents = std::fs::read_to_string(&file).expect("Couldn't read file"); diff --git a/src/mods/search.rs b/src/mods/search.rs index bd3a090..e6f5291 100644 --- a/src/mods/search.rs +++ b/src/mods/search.rs @@ -2,7 +2,7 @@ use crate::mods::strs::{err_rec, err_unrec, succ}; use ansi_term::Colour; 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); 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") .arg("-Ss") .arg(&pkg) diff --git a/src/mods/strs.rs b/src/mods/strs.rs index 24aa30a..4b1f542 100644 --- a/src/mods/strs.rs +++ b/src/mods/strs.rs @@ -2,7 +2,7 @@ use ansi_term::Colour; use std::{env, io, io::Write, process, string}; 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" { 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" { 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" { 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" { 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" { 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" { println!( "{} {}", diff --git a/src/mods/uninstall.rs b/src/mods/uninstall.rs index 45a79c7..e910593 100644 --- a/src/mods/uninstall.rs +++ b/src/mods/uninstall.rs @@ -5,7 +5,7 @@ use crate::mods::{ use runas::Command; use std::{fs, path::Path}; -pub fn uninstall(noconfirm: bool, pkgs: Vec) { +pub fn uninstall(noconfirm: bool, pkgs: Vec) { // uninstall a package sec(format!( "Attempting to uninstall packages: {}", &pkgs.join(" ") @@ -59,7 +59,7 @@ pub fn uninstall(noconfirm: bool, pkgs: Vec) { } } -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 = Vec::new(); let mut contents = String::new(); contents = std::fs::read_to_string(&file).expect("Couldn't read file"); diff --git a/src/mods/update.rs b/src/mods/update.rs index 214f485..6d8cd47 100644 --- a/src/mods/update.rs +++ b/src/mods/update.rs @@ -1,7 +1,7 @@ use crate::mods::strs::{err_unrec, sec, succ}; use runas::Command; -pub fn update() { +pub fn update() { // update the repositories sec(format!("Syncing package repos")); let result = Command::new("pacman") diff --git a/src/mods/upgrade.rs b/src/mods/upgrade.rs index c88e711..a5f1662 100644 --- a/src/mods/upgrade.rs +++ b/src/mods/upgrade.rs @@ -6,7 +6,7 @@ use runas::Command; use std::{env, fs, path::Path}; 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(); if make_depends.len() != 0 { @@ -23,7 +23,7 @@ fn uninstall_make_depend(pkg: &str) { 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 cachedir = format!("/{}/.cache/ame/", homepath); let cache_exists = Path::new(&format!("/{}/.cache/ame/", homepath)).is_dir(); diff --git a/src/mods/ver.rs b/src/mods/ver.rs index ba56bdf..02a756c 100644 --- a/src/mods/ver.rs +++ b/src/mods/ver.rs @@ -2,7 +2,7 @@ use crate::inf; use ansi_term::Colour; use clap::{self, crate_version}; -pub fn ver() { +pub fn ver() { // print version and contributors println!(""); inf(format!("ame - {}",crate_version!())); println!(""); diff --git a/src/mods/xargs.rs b/src/mods/xargs.rs index 95f9990..14664fd 100644 --- a/src/mods/xargs.rs +++ b/src/mods/xargs.rs @@ -1,4 +1,4 @@ -pub fn noconf(args: &Vec) -> bool { +pub fn noconf(args: &Vec) -> 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()) { true } else { @@ -6,7 +6,7 @@ pub fn noconf(args: &Vec) -> bool { } } -pub fn argssort(args: &mut Vec) -> &Vec { +pub fn argssort(args: &mut Vec) -> &Vec { // sort the args if args.contains(&"--noconfirm".to_string()) { args.retain(|x| x != &"--noconfirm".to_string()); args