From 64fbf606dfa0d6d845294c344ff8a3d7dcfc5958 Mon Sep 17 00:00:00 2001 From: chhe Date: Mon, 6 Jul 2020 13:36:45 +0200 Subject: [PATCH] option to use choco with gsudo on windows (#463) --- src/config.rs | 11 +++++++++++ src/steps/os/windows.rs | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 599783fe..282662ea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -129,6 +129,7 @@ pub struct Vagrant { pub struct Windows { accept_all_updates: Option, self_rename: Option, + use_gsudo_with_choco: Option, } #[derive(Deserialize, Default, Debug)] @@ -519,6 +520,16 @@ impl Config { .unwrap_or(false) } + /// Whether to use gsudo command with choco if available + #[allow(dead_code)] + pub fn use_gsudo_with_choco(&self) -> bool { + self.config_file + .windows + .as_ref() + .and_then(|w| w.use_gsudo_with_choco) + .unwrap_or(false) + } + /// Whether Brew cask should be greedy #[allow(dead_code)] pub fn brew_cask_greedy(&self) -> bool { diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index 68370489..04315010 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -3,19 +3,31 @@ use crate::execution_context::ExecutionContext; use crate::executor::{CommandExt, RunType}; use crate::powershell; use crate::terminal::print_separator; -use crate::utils::require; +use crate::utils::{require, which}; use anyhow::Result; use std::process::Command; pub fn run_chocolatey(ctx: &ExecutionContext) -> Result<()> { let choco = require("choco")?; let yes = ctx.config().yes(); + let use_gsudo = ctx.config().use_gsudo_with_choco(); print_separator("Chocolatey"); - let mut command = ctx.run_type().execute(&choco); + let mut cmd = choco; + let mut args = vec!["upgrade", "all"]; - command.args(&["upgrade", "all"]); + if use_gsudo { + let gsudo = which("gsudo"); + if let Some(gsudo) = gsudo { + cmd = gsudo; + args = vec!["choco", "upgrade", "all"]; + } + } + + let mut command = ctx.run_type().execute(&cmd); + + command.args(&args); if yes { command.arg("--yes");