From 6ec581108d07cca976f48ecf52a788fa1d3624b6 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sun, 25 Aug 2024 14:54:12 -0600 Subject: [PATCH] fixup use clauses shared between unix and windows builds --- src/cmd/install.rs | 7 ++++--- src/run.rs | 17 ++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cmd/install.rs b/src/cmd/install.rs index ef398f5..33930fb 100644 --- a/src/cmd/install.rs +++ b/src/cmd/install.rs @@ -9,6 +9,9 @@ use tar::Archive; use tempdir::TempDir; use zip; +#[cfg(windows)] +use std::process::ExitStatus; + pub fn run( language: &languages::Language, github_repo: &GithubRepo, @@ -34,9 +37,6 @@ pub fn run( match ext { "exe" => { let release_dir = release_dir.into_os_string().into_string().unwrap(); - // let file = file.into_os_string().into_string().unwrap(); - // let cmd = format!("{file:}"); - exe_run(file, release_dir.clone())?; Ok(release_dir) } @@ -65,6 +65,7 @@ fn exe_run(_cmd: PathBuf, _release_dir: String) -> Result<(), Report> { #[cfg(windows)] fn exe_run(file: PathBuf, release_dir: String) -> Result { use std::os::windows::process::CommandExt; + use std::process::Command; use windows_sys::Win32::Foundation::{BOOL, FALSE, TRUE}; use windows_sys::Win32::System::Console::SetConsoleCtrlHandler; diff --git a/src/run.rs b/src/run.rs index ecaadbb..f96cfd6 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,13 +1,11 @@ -use color_eyre::{eyre::Report, eyre::Result}; +use color_eyre::eyre::Result; use std::env::Args; use crate::config; use std::path::*; use std::process::Command; -#[cfg(windows)] -use std::process::ExitStatus; -pub fn run(bin: &str, args: Args) -> Result<(), Report> { +pub fn run(bin: &str, args: Args) -> Result<()> { // no -c argument available in this case let dir = config::install_to_use(bin)?; let cmd = Path::new(&dir).join("bin").join(bin); @@ -21,14 +19,14 @@ pub fn run(bin: &str, args: Args) -> Result<(), Report> { } #[cfg(unix)] -fn exec(cmd: &mut Command) -> Result<(), Report> { +fn exec(cmd: &mut Command) -> Result<()> { use std::os::unix::prelude::*; Err(cmd.exec().into()) } // thanks rustup command.rs #[cfg(windows)] -fn exec(cmd: &mut Command) -> Result { +fn exec(cmd: &mut Command) -> Result<()> { use color_eyre::eyre::eyre; use windows_sys::Win32::Foundation::{BOOL, FALSE, TRUE}; use windows_sys::Win32::System::Console::SetConsoleCtrlHandler; @@ -43,5 +41,10 @@ fn exec(cmd: &mut Command) -> Result { } } - Ok(cmd.status()?) + let status = cmd.status()?; + if !status.success() { + std::process::exit(status.code().unwrap_or(0)) + } + + Ok(()) }