Merge branch 'testing'

This commit is contained in:
Beefki 2017-10-24 03:04:33 -05:00
commit b06fc99e9e
2 changed files with 29 additions and 29 deletions

View File

@ -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?");
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");
}
}else {
while prog.first().is_some() {
let mut child = Command::new(&command).arg(prog.remove(0)).arg(term).spawn().expect("Broken3?");
},
(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

View File

@ -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<PackageManager> = vec![pacmatic, pacman, aptget, xbps];
//let managers: Vec<PackageManager> = 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);
}
}