Reduced hacky code

This commit is contained in:
Beefki 2017-10-24 03:02:20 -05:00
parent faad2908a2
commit 9a43c907ba

View File

@ -11,7 +11,7 @@ impl Config {
/// and loads the appropriate data from the passed `PackageManager`. /// and loads the appropriate data from the passed `PackageManager`.
/// Finally calls the program and passes the appropriate arguments /// Finally calls the program and passes the appropriate arguments
pub fn run(&self, pac: PackageManager) { pub fn run(&self, pac: PackageManager) {
let vec = match self.action { let get = match self.action {
Management::Search => pac.search, Management::Search => pac.search,
Management::Install => pac.install, Management::Install => pac.install,
Management::Uninstall => pac.uninstall, Management::Uninstall => pac.uninstall,
@ -23,34 +23,42 @@ impl Config {
Management::CompleteClear => pac.complete_cache_clear, Management::CompleteClear => pac.complete_cache_clear,
}; };
let mut prog = match vec { let mut prog = match get {
None => { 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(x) => x, Some(vec) => vec,
}; };
let command = prog.remove(0); let command = prog.remove(0);
let term = match &self.term { match (prog.first(), &self.term) {
&None => "", (None, _) => {
&Some(ref val) => val, let mut child = Command::new(&command).spawn().expect(
}; "Failed to open package manager"
);
if prog.first().is_none() { child.wait().expect("Failed to wait on package manager");
let mut child = Command::new(&command).spawn().expect("Broken?"); },
child.wait().expect("Failed to wait on child"); (_, &None) => {
}else if self.term.is_none() { for arg in prog.iter() {
while prog.first().is_some() { let mut child =Command::new(&command)
let mut child = Command::new(&command).arg(prog.remove(0)).spawn().expect("Broken2?"); .arg(arg)
child.wait().expect("Failed to wait on child"); .spawn()
} .expect("Failed to open package manager");
}else { child.wait().expect("Failed to wait on child");
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"); (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 /// Creates a `Config` from passed arguments, parses the `Management` enum