option to use choco with gsudo on windows (#463)

This commit is contained in:
chhe
2020-07-06 13:36:45 +02:00
committed by GitHub
parent 5c7f04c2cf
commit 64fbf606df
2 changed files with 26 additions and 3 deletions

View File

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