refactor: unify the behavior of the steps that require sudo (#467)

This commit is contained in:
SteveLauC
2023-06-13 22:15:57 +08:00
committed by GitHub
parent a7ddf4575a
commit 30858780cf
11 changed files with 265 additions and 309 deletions

View File

@@ -4,7 +4,7 @@ use std::os::unix::fs::MetadataExt;
use std::path::PathBuf;
use std::process::Command;
use crate::utils::require_option;
use crate::utils::{require_option, REQUIRE_SUDO};
use crate::HOME_DIR;
use color_eyre::eyre::Result;
#[cfg(target_os = "linux")]
@@ -92,7 +92,7 @@ impl NPM {
fn upgrade(&self, ctx: &ExecutionContext, use_sudo: bool) -> Result<()> {
let args = ["update", self.global_location_arg()];
if use_sudo {
let sudo = require_option(ctx.sudo().clone(), String::from("sudo is not installed"))?;
let sudo = require_option(ctx.sudo().clone(), REQUIRE_SUDO.to_string())?;
ctx.run_type()
.execute(sudo)
.arg(&self.command)
@@ -156,7 +156,7 @@ impl Yarn {
let args = ["global", "upgrade"];
if use_sudo {
let sudo = require_option(ctx.sudo().clone(), String::from("sudo is not installed"))?;
let sudo = require_option(ctx.sudo().clone(), REQUIRE_SUDO.to_string())?;
ctx.run_type()
.execute(sudo)
.arg(self.yarn.as_ref().unwrap_or(&self.command))