diff --git a/src/main.rs b/src/main.rs index d38fcba3..78e1a288 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,12 @@ fn run() -> Result<(), Error> { } } + #[cfg(windows)] + let powershell = windows::Powershell::new(); + + #[cfg(windows)] + report(&mut reports, powershell.update_modules(&mut terminal)); + if !(matches.is_present("no_system")) { #[cfg(target_os = "linux")] report(&mut reports, linux::upgrade(&sudo, &mut terminal)); diff --git a/src/windows.rs b/src/windows.rs index ca966696..ff427d48 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,6 +1,7 @@ use super::terminal::Terminal; -use super::utils::{self, Check}; +use super::utils::{self, which, Check}; use failure; +use std::path::PathBuf; use std::process::Command; #[must_use] @@ -18,3 +19,31 @@ pub fn run_chocolatey(terminal: &mut Terminal) -> Option<(&'static str, bool)> { None } + +pub struct Powershell { + path: Option, +} + +impl Powershell { + pub fn new() -> Self { + Powershell { + path: which("powershell"), + } + } + + #[must_use] + pub fn update_modules(&self, terminal: &mut Terminal) -> Option<(&'static str, bool)> { + if let Some(powershell) = &self.path { + terminal.print_separator("Powershell Module Update"); + + let success = || -> Result<(), failure::Error> { + Command::new(&powershell).arg("Update-Module").spawn()?.wait()?.check()?; + Ok(()) + }().is_ok(); + + return Some(("Powershell Module Update", success)); + } + + None + } +}