Powershell module update (fix #41)

This commit is contained in:
Roey Darwish Dror
2018-08-22 22:01:06 +03:00
parent 38f81aaa5a
commit 0d584bb7c0
2 changed files with 36 additions and 1 deletions

View File

@@ -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));

View File

@@ -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<PathBuf>,
}
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
}
}