Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Only update Powershell modules if profile is present and allow disabl…
Browse files Browse the repository at this point in the history
…ing this step (fix #114)
  • Loading branch information
r-darwish committed Jan 27, 2019
1 parent df27021 commit 4f981fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub enum Step {
Emacs,
/// Don't upgrade ruby gems
Gem,

#[cfg(windows)]
/// Don't update Powershell modules
Powershell,
}

impl Step {
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ fn run() -> Result<(), Error> {
let powershell = windows::Powershell::new();

#[cfg(windows)]
report.push_result(execute(|| powershell.update_modules(run_type), opt.no_retry)?);
{
if powershell.profile().is_some() && !opt.disable.contains(&Step::Powershell) {
report.push_result(execute(|| powershell.update_modules(run_type), opt.no_retry)?);
}
}

#[cfg(target_os = "linux")]
let distribution = linux::Distribution::detect();
Expand Down
31 changes: 14 additions & 17 deletions src/steps/os/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::error::Error;
use crate::executor::{CommandExt, RunType};
use crate::terminal::{is_dumb, print_separator};
use crate::utils::{self, which};
use log::error;
use std::path::PathBuf;
use std::process::Command;

Expand Down Expand Up @@ -43,6 +42,7 @@ pub fn run_scoop(run_type: RunType) -> Option<(&'static str, bool)> {

pub struct Powershell {
path: Option<PathBuf>,
profile: Option<PathBuf>,
}

impl Powershell {
Expand All @@ -51,9 +51,17 @@ impl Powershell {
/// If the powershell binary is not found, or the current terminal is dumb
/// then the instance of this struct will skip all the powershell steps.
pub fn new() -> Self {
Powershell {
path: which("powershell").filter(|_| !is_dumb()),
}
let path = which("powershell").filter(|_| !is_dumb());

let profile = path.as_ref().and_then(|path| {
Command::new(path)
.args(&["-Command", "echo $profile"])
.check_output()
.map(|output| PathBuf::from(output.trim()))
.ok()
});

Powershell { path, profile }
}

pub fn has_command(powershell: &PathBuf, command: &str) -> bool {
Expand All @@ -66,19 +74,8 @@ impl Powershell {
.is_ok()
}

pub fn profile(&self) -> Option<PathBuf> {
if let Some(powershell) = &self.path {
let result = Command::new(powershell)
.args(&["-Command", "echo $profile"])
.check_output()
.map(|output| PathBuf::from(output.trim()));

match result {
Err(e) => error!("Error getting Powershell profile: {}", e),
Ok(path) => return Some(path),
}
}
None
pub fn profile(&self) -> Option<&PathBuf> {
self.profile.as_ref()
}

#[must_use]
Expand Down

0 comments on commit 4f981fd

Please sign in to comment.