Some comments and minor edits

This commit is contained in:
Beefki 2017-10-28 14:45:09 -05:00
parent d2190b10cf
commit f1ecfdd620
2 changed files with 21 additions and 10 deletions

View File

@ -2,6 +2,7 @@ use super::{std, help, PackageManager};
use management::Management; use management::Management;
use std::process::Command; use std::process::Command;
/// A struct to hold parsed arg data. /// A struct to hold parsed arg data.
// TODO?: update to take mutltiple terms?
#[derive(Debug)] #[derive(Debug)]
pub struct Config { pub struct Config {
pub action: Management, pub action: Management,
@ -25,21 +26,19 @@ impl Config {
Management::CompleteClear => pac.complete_cache_clear, Management::CompleteClear => pac.complete_cache_clear,
}; };
// takes `Some(Vec<&str>)` and returns `Vec<&str>` // takes `Option(Vec<&str>)` and returns `Vec<&str>` if `Some(_)`
// checks to make sure the package manager supports the action // If `None`, tell user and exit.
let mut prog = match get { let mut prog = get.unwrap_or_else(|| {
None => {
println!("Sorry, your package manager does not support this action"); println!("Sorry, your package manager does not support this action");
std::process::exit(0) std::process::exit(0)
}, });
Some(vec) => vec,
};
//Pop's from the front of the `Vec<&str>`, which should always be the command name //Pop's from the front of the `Vec<&str>`, which should always be the command name
let command = prog.remove(0); let command = prog.remove(0);
// Tuple match, `prog.first()` returns an `Option<T>` on the first element of // Tuple match, `prog.first()` returns an `Option<T>` on the first element of
// a Vec, `self.term` is also an `Option<T>` so this checks both for `Some`/`None` // a Vec, `self.term` is also an `Option<T>` 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) { match (prog.first(), &self.term) {
(None, &None) => { (None, &None) => {
let mut child = Command::new(&command).spawn().expect( let mut child = Command::new(&command).spawn().expect(

View File

@ -9,6 +9,9 @@ use config::Config;
use std::io; use std::io;
use std::path::PathBuf; use std::path::PathBuf;
/// Takes user input. `io::Result<T>` returns either `Ok(T)`
/// or `Err(io::Error)` Error handling is common on inputs so brevity
/// is nice.
fn input() -> io::Result<String> { fn input() -> io::Result<String> {
let mut val = String::new(); let mut val = String::new();
io::stdin().read_line(&mut val)?; io::stdin().read_line(&mut val)?;
@ -16,13 +19,17 @@ fn input() -> io::Result<String> {
} }
fn main() { fn main() {
//pulls in the args passed and stores them in a `Config` struct
let config = Config::new(); let config = Config::new();
//Sets a path to `~/.config/rux/`
let mut ruxconf = std::env::home_dir().unwrap_or_else(|| { let mut ruxconf = std::env::home_dir().unwrap_or_else(|| {
PathBuf::new() PathBuf::new()
}); });
ruxconf.push(".config/rux/rux.conf"); 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() { if ruxconf.is_file() {
let pac = read_default(ruxconf).unwrap_or_else(|err| { let pac = read_default(ruxconf).unwrap_or_else(|err| {
eprintln!("{:?}", err); eprintln!("{:?}", err);
@ -32,8 +39,13 @@ fn main() {
std::process::exit(0); std::process::exit(0);
} }
// Loads all PackageManagers into a Vec to search through
let managers = PackageManager::all(); let managers = PackageManager::all();
// Iterates through the `Vec<PackageManager>` 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; let mut found: bool = false;
for prog in managers { for prog in managers {
if found { if found {