From 9892fefd2f808e0fe7f86990ac3b59a1557599bc Mon Sep 17 00:00:00 2001 From: Beefki Date: Sat, 28 Oct 2017 14:45:09 -0500 Subject: [PATCH] Some comments and minor edits --- src/config.rs | 19 +++++++++---------- src/main.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index ad416db..c783585 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use super::{std, help, PackageManager}; use management::Management; use std::process::Command; /// A struct to hold parsed arg data. +// TODO?: update to take mutltiple terms? #[derive(Debug)] pub struct Config { pub action: Management, @@ -25,21 +26,19 @@ impl Config { Management::CompleteClear => pac.complete_cache_clear, }; - // takes `Some(Vec<&str>)` and returns `Vec<&str>` - // checks to make sure the package manager supports the action - let mut prog = match get { - None => { - println!("Sorry, your package manager does not support this action"); - std::process::exit(0) - }, - Some(vec) => vec, - }; + // takes `Option(Vec<&str>)` and returns `Vec<&str>` if `Some(_)` + // If `None`, tell user and exit. + let mut prog = get.unwrap_or_else(|| { + println!("Sorry, your package manager does not support this action"); + std::process::exit(0) + }); //Pop's from the front of the `Vec<&str>`, which should always be the command name let command = prog.remove(0); + // Tuple match, `prog.first()` returns an `Option` on the first element of // a Vec, `self.term` is also an `Option` so this checks both for `Some`/`None` - // and formats the program as needed + // and formats the program call as needed match (prog.first(), &self.term) { (None, &None) => { let mut child = Command::new(&command).spawn().expect( diff --git a/src/main.rs b/src/main.rs index 4f98d49..2507c04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,9 @@ use config::Config; use std::io; use std::path::PathBuf; +/// Takes user input. `io::Result` returns either `Ok(T)` +/// or `Err(io::Error)` Error handling is common on inputs so brevity +/// is nice. fn input() -> io::Result { let mut val = String::new(); io::stdin().read_line(&mut val)?; @@ -16,13 +19,17 @@ fn input() -> io::Result { } fn main() { + //pulls in the args passed and stores them in a `Config` struct let config = Config::new(); + //Sets a path to `~/.config/rux/` let mut ruxconf = std::env::home_dir().unwrap_or_else(|| { PathBuf::new() }); ruxconf.push(".config/rux/rux.conf"); + // Checks if `~/.config/rux/rux.conf` exists and skips loading any + // other package manager and searching for them. if ruxconf.is_file() { let pac = read_default(ruxconf).unwrap_or_else(|err| { eprintln!("{:?}", err); @@ -32,8 +39,13 @@ fn main() { std::process::exit(0); } + // Loads all PackageManagers into a Vec to search through let managers = PackageManager::all(); + // Iterates through the `Vec` until it finds a match, + // asks the user if they want to use that manager, and if they want to + // set it as default to ALWAYS use that manager. Finally sends all the + // needed information to run the package manager let mut found: bool = false; for prog in managers { if found {