Skip to content

Commit

Permalink
fixup use clauses shared between unix and windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Aug 26, 2024
1 parent b26c9d2 commit 6ec5811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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<ExitStatus, Report> {
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;

Expand Down
17 changes: 10 additions & 7 deletions src/run.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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<ExitStatus, Report> {
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;
Expand All @@ -43,5 +41,10 @@ fn exec(cmd: &mut Command) -> Result<ExitStatus, Report> {
}
}

Ok(cmd.status()?)
let status = cmd.status()?;
if !status.success() {
std::process::exit(status.code().unwrap_or(0))
}

Ok(())
}

0 comments on commit 6ec5811

Please sign in to comment.