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())
|
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> {
|
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(())
|
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]
|
#[must_use]
|
||||||
pub fn run_needrestart(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
pub fn run_needrestart(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
||||||
if let Some(sudo) = sudo {
|
if let Some(sudo) = sudo {
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@@ -108,14 +108,24 @@ fn run() -> Result<(), Error> {
|
|||||||
&mut terminal,
|
&mut terminal,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
let distribution = linux::Distribution::detect();
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
if !opt.no_system {
|
if !opt.no_system {
|
||||||
|
match distribution {
|
||||||
|
Ok(distribution) => {
|
||||||
report.push_result(execute(
|
report.push_result(execute(
|
||||||
|terminal| linux::upgrade(&sudo, terminal, opt.dry_run),
|
|terminal| distribution.upgrade(&sudo, terminal, opt.dry_run),
|
||||||
&mut terminal,
|
&mut terminal,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Error detecting current distribution: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|||||||
Reference in New Issue
Block a user