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 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<T>` on the first element of
// 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) {
(None, &None) => {
let mut child = Command::new(&command).spawn().expect(

View File

@ -9,6 +9,9 @@ use config::Config;
use std::io;
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> {
let mut val = String::new();
io::stdin().read_line(&mut val)?;
@ -16,13 +19,17 @@ fn input() -> io::Result<String> {
}
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<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;
for prog in managers {
if found {