Probably fix apt
This commit is contained in:
parent
47c00435e6
commit
4da3895bbe
@ -8,48 +8,61 @@ pub struct Config {
|
||||
|
||||
impl Config {
|
||||
/// 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
|
||||
pub fn run(&self, pac: PackageManager) -> Child {
|
||||
let prog = match self.action {
|
||||
Management::Search => (pac.search.0, pac.search.1.unwrap_or_else(|| "".to_string())),
|
||||
Management::Install => (
|
||||
pac.install.0,
|
||||
pac.install.1.unwrap_or_else(|| "".to_string()),
|
||||
),
|
||||
Management::Uninstall => (
|
||||
pac.uninstall.0,
|
||||
pac.uninstall.1.unwrap_or_else(|| "".to_string()),
|
||||
),
|
||||
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(),
|
||||
),
|
||||
),
|
||||
Management::Search => (pac.search.0, pac.search.1),
|
||||
Management::Install => (pac.install.0, pac.install.1),
|
||||
Management::Uninstall => (pac.uninstall.0, pac.uninstall.1),
|
||||
Management::Remove => (pac.purge.0, pac.purge.1),
|
||||
Management::Update => (pac.update.0, pac.update.1),
|
||||
Management::Upgrade => (pac.upgrade.0, pac.upgrade.1),
|
||||
Management::Full => (pac.sup.0, pac.sup.1),
|
||||
Management::Clear => (pac.cache_clear.0, pac.cache_clear.1),
|
||||
Management::CompleteClear => (pac.complete_cache_clear.0, pac.complete_cache_clear.1),
|
||||
};
|
||||
|
||||
/*
|
||||
let term = match self.term {
|
||||
None => "",
|
||||
Some(ref val) => val,
|
||||
};
|
||||
*/
|
||||
|
||||
Command::new(&prog.0)
|
||||
.arg(&prog.1)
|
||||
.arg(term)
|
||||
.spawn()
|
||||
.expect("Failed to call package manager")
|
||||
match (&prog.1, &self.term) {
|
||||
(&None, &None) => {
|
||||
Command::new(&prog.0).spawn().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
|
||||
/// 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;
|
||||
for prog in managers {
|
||||
if found { break }
|
||||
if found {
|
||||
break;
|
||||
}
|
||||
if prog.exe.is_file() {
|
||||
println!("Found {}, is this the manager you want to use? [Y/n]", prog.name);
|
||||
if input().unwrap().trim().to_lowercase() == "n" {
|
||||
continue
|
||||
}else {
|
||||
println!(
|
||||
"Found {}, is this the manager you want to use? [Y/n]",
|
||||
prog.name
|
||||
);
|
||||
if input().unwrap().trim().to_lowercase() == "n" {
|
||||
continue;
|
||||
} else {
|
||||
found = true;
|
||||
println!("Would you like to set {} as default? [y/N]", prog.name);
|
||||
if input().unwrap().trim().to_lowercase() == "y" {
|
||||
let check = prog.set_default();
|
||||
match check {
|
||||
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);
|
||||
child.wait().expect("Failed to wait on child");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user