Probably fix apt
This commit is contained in:
parent
47c00435e6
commit
4da3895bbe
@ -8,48 +8,61 @@ pub struct Config {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
/// Actually runs the package manager. Checks what command was requested
|
/// Actually runs the package manager. Checks what command was requested
|
||||||
/// 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) -> Child {
|
pub fn run(&self, pac: PackageManager) -> Child {
|
||||||
let prog = match self.action {
|
let prog = match self.action {
|
||||||
Management::Search => (pac.search.0, pac.search.1.unwrap_or_else(|| "".to_string())),
|
Management::Search => (pac.search.0, pac.search.1),
|
||||||
Management::Install => (
|
Management::Install => (pac.install.0, pac.install.1),
|
||||||
pac.install.0,
|
Management::Uninstall => (pac.uninstall.0, pac.uninstall.1),
|
||||||
pac.install.1.unwrap_or_else(|| "".to_string()),
|
Management::Remove => (pac.purge.0, pac.purge.1),
|
||||||
),
|
Management::Update => (pac.update.0, pac.update.1),
|
||||||
Management::Uninstall => (
|
Management::Upgrade => (pac.upgrade.0, pac.upgrade.1),
|
||||||
pac.uninstall.0,
|
Management::Full => (pac.sup.0, pac.sup.1),
|
||||||
pac.uninstall.1.unwrap_or_else(|| "".to_string()),
|
Management::Clear => (pac.cache_clear.0, pac.cache_clear.1),
|
||||||
),
|
Management::CompleteClear => (pac.complete_cache_clear.0, pac.complete_cache_clear.1),
|
||||||
Management::Remove => (pac.purge.0, pac.purge.1.unwrap_or_else(|| "".to_string())),
|
|
||||||
Management::Update => (pac.update.0, pac.update.1.unwrap_or_else(|| "".to_string())),
|
|
||||||
Management::Upgrade => (
|
|
||||||
pac.upgrade.0,
|
|
||||||
pac.upgrade.1.unwrap_or_else(|| "".to_string()),
|
|
||||||
),
|
|
||||||
Management::Full => (pac.sup.0, pac.sup.1.unwrap_or_else(|| "".to_string())),
|
|
||||||
Management::Clear => (
|
|
||||||
pac.cache_clear.0,
|
|
||||||
pac.cache_clear.1.unwrap_or_else(|| "".to_string()),
|
|
||||||
),
|
|
||||||
Management::CompleteClear => (
|
|
||||||
pac.complete_cache_clear.0,
|
|
||||||
pac.complete_cache_clear.1.unwrap_or_else(
|
|
||||||
|| "".to_string(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
let term = match self.term {
|
let term = match self.term {
|
||||||
None => "",
|
None => "",
|
||||||
Some(ref val) => val,
|
Some(ref val) => val,
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
Command::new(&prog.0)
|
match (&prog.1, &self.term) {
|
||||||
.arg(&prog.1)
|
(&None, &None) => {
|
||||||
.arg(term)
|
Command::new(&prog.0).spawn().expect(
|
||||||
.spawn()
|
"Failed to call package manager",
|
||||||
.expect("Failed to call package manager")
|
)
|
||||||
|
}
|
||||||
|
(&Some(ref arg), &None) => {
|
||||||
|
Command::new(&prog.0).arg(arg).spawn().expect(
|
||||||
|
"Failed to call package manager",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
(&Some(ref arg1), &Some(ref arg2)) => {
|
||||||
|
Command::new(&prog.0).arg(arg1).arg(arg2).spawn().expect(
|
||||||
|
"Failed to call package manager",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("{:?}, {:?}", &prog.1, &self.term);
|
||||||
|
println!("Arguments formed incorrectly, no action taken");
|
||||||
|
std::process::exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if prog.1.is_none() && self.term.is_none() {
|
||||||
|
}else{
|
||||||
|
Command::new(&prog.0)
|
||||||
|
.arg(&prog.1)
|
||||||
|
.arg(term)
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to call package manager")
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
/// Creates a `Config` from passed arguments, parses the `Management` enum
|
/// Creates a `Config` from passed arguments, parses the `Management` enum
|
||||||
/// and term (if any). Requires an action, while the term can be `None`.
|
/// and term (if any). Requires an action, while the term can be `None`.
|
||||||
|
25
src/main.rs
25
src/main.rs
@ -37,24 +37,33 @@ fn main() {
|
|||||||
|
|
||||||
let mut found: bool = false;
|
let mut found: bool = false;
|
||||||
for prog in managers {
|
for prog in managers {
|
||||||
if found { break }
|
if found {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if prog.exe.is_file() {
|
if prog.exe.is_file() {
|
||||||
println!("Found {}, is this the manager you want to use? [Y/n]", prog.name);
|
println!(
|
||||||
if input().unwrap().trim().to_lowercase() == "n" {
|
"Found {}, is this the manager you want to use? [Y/n]",
|
||||||
continue
|
prog.name
|
||||||
}else {
|
);
|
||||||
|
if input().unwrap().trim().to_lowercase() == "n" {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
found = true;
|
found = true;
|
||||||
println!("Would you like to set {} as default? [y/N]", prog.name);
|
println!("Would you like to set {} as default? [y/N]", prog.name);
|
||||||
if input().unwrap().trim().to_lowercase() == "y" {
|
if input().unwrap().trim().to_lowercase() == "y" {
|
||||||
let check = prog.set_default();
|
let check = prog.set_default();
|
||||||
match check {
|
match check {
|
||||||
Ok(_) => println!("Default set"),
|
Ok(_) => println!("Default set"),
|
||||||
Err(err) => println!("An error occured while setting default:\
|
Err(err) => {
|
||||||
{}", err)
|
println!(
|
||||||
|
"An error occured while setting default:\
|
||||||
|
{}",
|
||||||
|
err
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//let mut child = call(prog, &config.action, &config.term.clone().unwrap_or_else(|| "".to_string()));
|
|
||||||
let mut child = config.run(prog);
|
let mut child = config.run(prog);
|
||||||
child.wait().expect("Failed to wait on child");
|
child.wait().expect("Failed to wait on child");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user