Skip to content

Commit 9fd37c4

Browse files
fix(cli): improve Windows compatibility for self-update
- Use 'where' instead of 'which' on Windows - Use PowerShell's Invoke-WebRequest on Windows (with curl fallback) - Fix clippy warning about uninlined format args
1 parent 3a3fe07 commit 9fd37c4

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

raz-adapters/cli/src/main.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,8 @@ async fn handle_self_update(force: bool) -> anyhow::Result<()> {
843843

844844
if !is_cargo_installed {
845845
// Check if it's in system PATH but not cargo
846-
let which_result = process::Command::new("which").arg("raz").output();
846+
let which_cmd = if cfg!(windows) { "where" } else { "which" };
847+
let which_result = process::Command::new(which_cmd).arg("raz").output();
847848

848849
if let Ok(output) = which_result {
849850
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
@@ -930,10 +931,29 @@ async fn get_latest_version() -> anyhow::Result<String> {
930931
// Get all releases, not just the "latest" (which might be wrong)
931932
let url = "https://api.github.com/repos/codeitlikemiley/raz/releases?per_page=20";
932933

933-
// Use a simple HTTPS request
934-
let output = process::Command::new("curl")
935-
.args(["-s", "-H", "Accept: application/vnd.github.v3+json", url])
936-
.output()?;
934+
// Use platform-appropriate HTTP client
935+
let output = if cfg!(windows) {
936+
// Try PowerShell on Windows
937+
process::Command::new("powershell")
938+
.args([
939+
"-Command",
940+
&format!(
941+
"Invoke-WebRequest -Uri '{url}' -Headers @{{'Accept'='application/vnd.github.v3+json'}} -UseBasicParsing | Select-Object -ExpandProperty Content"
942+
),
943+
])
944+
.output()
945+
.or_else(|_| {
946+
// Fallback to curl if available on Windows
947+
process::Command::new("curl")
948+
.args(["-s", "-H", "Accept: application/vnd.github.v3+json", url])
949+
.output()
950+
})?
951+
} else {
952+
// Use curl on Unix-like systems
953+
process::Command::new("curl")
954+
.args(["-s", "-H", "Accept: application/vnd.github.v3+json", url])
955+
.output()?
956+
};
937957

938958
if !output.status.success() {
939959
anyhow::bail!("Failed to fetch versions from GitHub");

0 commit comments

Comments
 (0)