diff --git a/src/linux.rs b/src/linux.rs index b9c780a1..70cb62af 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -48,6 +48,25 @@ impl Distribution { Err(UnknownLinuxDistribution.into()) } + + #[must_use] + pub fn upgrade( + self, + sudo: &Option, + 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, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { @@ -125,26 +144,6 @@ fn upgrade_debian(sudo: &Option, terminal: &mut Terminal, dry_run: bool Ok(()) } -#[must_use] -pub fn upgrade(sudo: &Option, 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, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { if let Some(sudo) = sudo { diff --git a/src/main.rs b/src/main.rs index 00e830d8..11b31ead 100644 --- a/src/main.rs +++ b/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); + } + } } }