Explictly handle package manager outcomes
This commit is contained in:
parent
27b87f7da2
commit
fd16e0c21b
@ -23,6 +23,7 @@ impl Config {
|
|||||||
Management::CompleteClear => pac.complete_cache_clear,
|
Management::CompleteClear => pac.complete_cache_clear,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// takes `Some(Vec<&str>)` and returns `Vec<&str>`
|
||||||
let mut prog = match get {
|
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");
|
||||||
@ -31,16 +32,25 @@ impl Config {
|
|||||||
Some(vec) => vec,
|
Some(vec) => vec,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Pop's from the front of the `Vec<&str>`, which should always be the command name
|
||||||
let command = prog.remove(0);
|
let command = prog.remove(0);
|
||||||
|
// Matches against a tuple of the first element of the `Vec` and the `&Option<String>`
|
||||||
|
// from the passed `Config`, taking a reference to that data when it needs it.
|
||||||
match (prog.first(), &self.term) {
|
match (prog.first(), &self.term) {
|
||||||
(None, _) => {
|
(None, &None) => {
|
||||||
let mut child = Command::new(&command).spawn().expect(
|
let mut child = Command::new(&command).spawn().expect(
|
||||||
"Failed to open package manager"
|
"Failed to open package manager"
|
||||||
);
|
);
|
||||||
child.wait().expect("Failed to wait on 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 {
|
for arg in &prog {
|
||||||
let mut child =Command::new(&command)
|
let mut child =Command::new(&command)
|
||||||
.arg(arg)
|
.arg(arg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user