Skip to content

Commit

Permalink
Use gcloud.cmd to invoke gcloud on Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andreban authored and djc committed May 29, 2024
1 parent 5d93e26 commit 7fe074d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/gcloud_authorized_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl TokenProvider for GCloudAuthorizedUser {
}

fn run(cmd: &[&str]) -> Result<String, Error> {
let mut command = Command::new("gcloud");
let mut command = Command::new(GCLOUD_CMD);
command.args(cmd);

let mut stdout = match command.output() {
Expand All @@ -75,6 +75,12 @@ fn run(cmd: &[&str]) -> Result<String, Error> {
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.
Expand Down

0 comments on commit 7fe074d

Please sign in to comment.