From faad2908a2300905eb69bc07fffbc0725bb73854 Mon Sep 17 00:00:00 2001 From: Beefki Date: Mon, 23 Oct 2017 16:07:44 -0500 Subject: [PATCH 1/2] Cleaning up some comments --- src/main.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2aed628..4415e42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,8 +23,6 @@ fn main() { if Path::new("default.conf").is_file() { let pac = read_default(); config.run(pac); - //let mut child = config.run(pac); - //child.wait().expect("Failed to wait on child"); std::process::exit(0); } @@ -34,7 +32,6 @@ fn main() { let xbps = PackageManager::xbps(); let managers: Vec = vec![pacmatic, pacman, aptget, xbps]; - //let managers: Vec = vec![pacmatic]; let mut found: bool = false; for prog in managers { @@ -64,11 +61,6 @@ fn main() { } } } - - /* - let mut child = config.run(prog); - child.wait().expect("Failed to wait on child"); - */ config.run(prog); } } From 9a43c907bad6f32e50fead0fc991be1383ecce36 Mon Sep 17 00:00:00 2001 From: Beefki Date: Tue, 24 Oct 2017 03:02:20 -0500 Subject: [PATCH 2/2] Reduced hacky code --- src/config.rs | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3c5a5b0..26db932 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,7 +11,7 @@ impl Config { /// and loads the appropriate data from the passed `PackageManager`. /// Finally calls the program and passes the appropriate arguments pub fn run(&self, pac: PackageManager) { - let vec = match self.action { + let get = match self.action { Management::Search => pac.search, Management::Install => pac.install, Management::Uninstall => pac.uninstall, @@ -23,34 +23,42 @@ impl Config { Management::CompleteClear => pac.complete_cache_clear, }; - let mut prog = match vec { + let mut prog = match get { None => { println!("Sorry, your package manager does not support this action"); std::process::exit(0); }, - Some(x) => x, + Some(vec) => vec, }; let command = prog.remove(0); - let term = match &self.term { - &None => "", - &Some(ref val) => val, - }; - - if prog.first().is_none() { - let mut child = Command::new(&command).spawn().expect("Broken?"); - child.wait().expect("Failed to wait on child"); - }else if self.term.is_none() { - while prog.first().is_some() { - let mut child = Command::new(&command).arg(prog.remove(0)).spawn().expect("Broken2?"); - child.wait().expect("Failed to wait on child"); - } - }else { - while prog.first().is_some() { - let mut child = Command::new(&command).arg(prog.remove(0)).arg(term).spawn().expect("Broken3?"); - child.wait().expect("Failed to wait on child"); - } + match (prog.first(), &self.term) { + (None, _) => { + let mut child = Command::new(&command).spawn().expect( + "Failed to open package manager" + ); + child.wait().expect("Failed to wait on package manager"); + }, + (_, &None) => { + for arg in prog.iter() { + let mut child =Command::new(&command) + .arg(arg) + .spawn() + .expect("Failed to open package manager"); + child.wait().expect("Failed to wait on child"); + } + }, + (Some(_), &Some(ref term)) => { + for arg in prog.iter() { + let mut child = Command::new(&command) + .arg(arg) + .arg(term) + .spawn() + .expect("Failed to open package manager"); + child.wait().expect("Failed to wait on child"); + } + }, } } /// Creates a `Config` from passed arguments, parses the `Management` enum