Make the linux upgrade function a method
This commit is contained in:
39
src/linux.rs
39
src/linux.rs
@@ -48,6 +48,25 @@ impl Distribution {
|
||||
|
||||
Err(UnknownLinuxDistribution.into())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn upgrade(
|
||||
self,
|
||||
sudo: &Option<PathBuf>,
|
||||
terminal: &mut Terminal,
|
||||
dry_run: bool,
|
||||
) -> Option<(&'static str, bool)> {
|
||||
terminal.print_separator("System update");
|
||||
|
||||
let success = match self {
|
||||
Distribution::Arch => upgrade_arch_linux(&sudo, terminal, dry_run),
|
||||
Distribution::CentOS => upgrade_redhat(&sudo, terminal, dry_run),
|
||||
Distribution::Fedora => upgrade_fedora(&sudo, terminal, dry_run),
|
||||
Distribution::Ubuntu | Distribution::Debian => upgrade_debian(&sudo, terminal, dry_run),
|
||||
};
|
||||
|
||||
Some(("System update", success.is_ok()))
|
||||
}
|
||||
}
|
||||
|
||||
fn upgrade_arch_linux(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> {
|
||||
@@ -125,26 +144,6 @@ fn upgrade_debian(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn upgrade(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
||||
terminal.print_separator("System update");
|
||||
|
||||
let success = match Distribution::detect() {
|
||||
Ok(distribution) => match distribution {
|
||||
Distribution::Arch => upgrade_arch_linux(&sudo, terminal, dry_run),
|
||||
Distribution::CentOS => upgrade_redhat(&sudo, terminal, dry_run),
|
||||
Distribution::Fedora => upgrade_fedora(&sudo, terminal, dry_run),
|
||||
Distribution::Ubuntu | Distribution::Debian => upgrade_debian(&sudo, terminal, dry_run),
|
||||
}.is_ok(),
|
||||
Err(e) => {
|
||||
println!("Error detecting current distribution: {}", e);
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
Some(("System update", success))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_needrestart(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
||||
if let Some(sudo) = sudo {
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -108,13 +108,23 @@ fn run() -> Result<(), Error> {
|
||||
&mut terminal,
|
||||
));
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
let distribution = linux::Distribution::detect();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if !opt.no_system {
|
||||
report.push_result(execute(
|
||||
|terminal| linux::upgrade(&sudo, terminal, opt.dry_run),
|
||||
&mut terminal,
|
||||
));
|
||||
match distribution {
|
||||
Ok(distribution) => {
|
||||
report.push_result(execute(
|
||||
|terminal| distribution.upgrade(&sudo, terminal, opt.dry_run),
|
||||
&mut terminal,
|
||||
));
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error detecting current distribution: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user