From 7fe074dfa167891954b35e76e7a0213ad501278d Mon Sep 17 00:00:00 2001 From: Andre Bandarra Date: Wed, 29 May 2024 12:52:24 +0100 Subject: [PATCH] Use `gcloud.cmd` to invoke `gcloud` on Windows On Windows, the name of the `gcloud` command is `gcloud.cmd`, while on MacOS and Linux the name is just `gcloud`. While on the Windows Command prompt invoking `gcloud` works, this is not the case when a process is spawned with Rust's `Command`, causing the application to fail to execute the command. As a solution, we introduce an OS specific variable reflecting the actual command name for each OS. --- src/gcloud_authorized_user.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gcloud_authorized_user.rs b/src/gcloud_authorized_user.rs index 30b11a6..ffc6e59 100644 --- a/src/gcloud_authorized_user.rs +++ b/src/gcloud_authorized_user.rs @@ -59,7 +59,7 @@ impl TokenProvider for GCloudAuthorizedUser { } fn run(cmd: &[&str]) -> Result { - let mut command = Command::new("gcloud"); + let mut command = Command::new(GCLOUD_CMD); command.args(cmd); let mut stdout = match command.output() { @@ -75,6 +75,12 @@ fn run(cmd: &[&str]) -> Result { String::from_utf8(stdout).map_err(|_| Error::Str("output from `gcloud` is not UTF-8")) } +#[cfg(any(target_os = "linux", target_os = "macos"))] +const GCLOUD_CMD: &str = "gcloud"; + +#[cfg(target_os = "windows")] +const GCLOUD_CMD: &str = "gcloud.cmd"; + /// The default number of seconds that it takes for a Google Cloud auth token to expire. /// This appears to be the default from practical testing, but we have not found evidence /// that this will always be the default duration.