From fd16e0c21bcc27cd0656258412717a2fd2e88d51 Mon Sep 17 00:00:00 2001 From: Beefki Date: Tue, 24 Oct 2017 10:52:04 -0500 Subject: [PATCH] Explictly handle package manager outcomes --- src/config.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 89576cb..48631e3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,6 +23,7 @@ impl Config { Management::CompleteClear => pac.complete_cache_clear, }; + // takes `Some(Vec<&str>)` and returns `Vec<&str>` let mut prog = match get { None => { println!("Sorry, your package manager does not support this action"); @@ -31,16 +32,25 @@ impl Config { Some(vec) => vec, }; + //Pop's from the front of the `Vec<&str>`, which should always be the command name let command = prog.remove(0); - + // Matches against a tuple of the first element of the `Vec` and the `&Option` + // from the passed `Config`, taking a reference to that data when it needs it. match (prog.first(), &self.term) { - (None, _) => { + (None, &None) => { let mut child = Command::new(&command).spawn().expect( "Failed to open package manager" ); child.wait().expect("Failed to wait on package manager"); }, - (_, &None) => { + (None, &Some(ref term)) => { + let mut child = Command::new(&command) + .arg(term) + .spawn() + .expect("Failed to open package manager"); + child.wait().expect("Failed to wait on package manager"); + }, + (Some(_), &None) => { for arg in &prog { let mut child =Command::new(&command) .arg(arg)