Only update Powershell modules if profile is present and allow disabling this step (fix #114)
This commit is contained in:
@@ -39,6 +39,10 @@ pub enum Step {
|
|||||||
Emacs,
|
Emacs,
|
||||||
/// Don't upgrade ruby gems
|
/// Don't upgrade ruby gems
|
||||||
Gem,
|
Gem,
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
/// Don't update Powershell modules
|
||||||
|
Powershell,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Step {
|
impl Step {
|
||||||
|
|||||||
@@ -96,7 +96,11 @@ fn run() -> Result<(), Error> {
|
|||||||
let powershell = windows::Powershell::new();
|
let powershell = windows::Powershell::new();
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[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")]
|
#[cfg(target_os = "linux")]
|
||||||
let distribution = linux::Distribution::detect();
|
let distribution = linux::Distribution::detect();
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use crate::error::Error;
|
|||||||
use crate::executor::{CommandExt, RunType};
|
use crate::executor::{CommandExt, RunType};
|
||||||
use crate::terminal::{is_dumb, print_separator};
|
use crate::terminal::{is_dumb, print_separator};
|
||||||
use crate::utils::{self, which};
|
use crate::utils::{self, which};
|
||||||
use log::error;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
@@ -43,6 +42,7 @@ pub fn run_scoop(run_type: RunType) -> Option<(&'static str, bool)> {
|
|||||||
|
|
||||||
pub struct Powershell {
|
pub struct Powershell {
|
||||||
path: Option<PathBuf>,
|
path: Option<PathBuf>,
|
||||||
|
profile: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Powershell {
|
impl Powershell {
|
||||||
@@ -51,9 +51,17 @@ impl Powershell {
|
|||||||
/// If the powershell binary is not found, or the current terminal is dumb
|
/// 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.
|
/// then the instance of this struct will skip all the powershell steps.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Powershell {
|
let path = which("powershell").filter(|_| !is_dumb());
|
||||||
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 {
|
pub fn has_command(powershell: &PathBuf, command: &str) -> bool {
|
||||||
@@ -66,19 +74,8 @@ impl Powershell {
|
|||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn profile(&self) -> Option<PathBuf> {
|
pub fn profile(&self) -> Option<&PathBuf> {
|
||||||
if let Some(powershell) = &self.path {
|
self.profile.as_ref()
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|||||||
Reference in New Issue
Block a user