Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/publish-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ jobs:
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
build-tool: cross
- target: x86_64-pc-windows-msvc
os: windows-latest
build-tool: cargo
- target: aarch64-pc-windows-msvc
os: windows-latest
build-tool: cargo
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
Expand Down
14 changes: 10 additions & 4 deletions lib/src/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ use xx::process::check_status;
use xx::{XXError, XXResult};

pub(crate) fn sh(script: &str) -> XXResult<String> {
let output = Command::new("sh")
.arg("-c")
#[cfg(unix)]
let (shell, flag) = ("sh", "-c");

#[cfg(windows)]
let (shell, flag) = ("cmd", "/c");

let output = Command::new(shell)
.arg(flag)
.arg(script)
.stdin(std::process::Stdio::null())
.stderr(std::process::Stdio::inherit())
.env("__USAGE", env!("CARGO_PKG_VERSION"))
.output()
.map_err(|err| XXError::ProcessError(err, format!("sh -c {script}")))?;
.map_err(|err| XXError::ProcessError(err, format!("{shell} {flag} {script}")))?;

check_status(output.status)
.map_err(|err| XXError::ProcessError(err, format!("sh -c {script}")))?;
.map_err(|err| XXError::ProcessError(err, format!("{shell} {flag} {script}")))?;
let stdout = String::from_utf8(output.stdout).expect("stdout is not utf-8");
Ok(stdout)
}