Skip to content

Commit 7fe074d

Browse files
andrebandjc
authored andcommitted
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.
1 parent 5d93e26 commit 7fe074d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/gcloud_authorized_user.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl TokenProvider for GCloudAuthorizedUser {
5959
}
6060

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

6565
let mut stdout = match command.output() {
@@ -75,6 +75,12 @@ fn run(cmd: &[&str]) -> Result<String, Error> {
7575
String::from_utf8(stdout).map_err(|_| Error::Str("output from `gcloud` is not UTF-8"))
7676
}
7777

78+
#[cfg(any(target_os = "linux", target_os = "macos"))]
79+
const GCLOUD_CMD: &str = "gcloud";
80+
81+
#[cfg(target_os = "windows")]
82+
const GCLOUD_CMD: &str = "gcloud.cmd";
83+
7884
/// The default number of seconds that it takes for a Google Cloud auth token to expire.
7985
/// This appears to be the default from practical testing, but we have not found evidence
8086
/// that this will always be the default duration.

0 commit comments

Comments
 (0)