Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 0f1dc36

Browse files
committed
simplify heroku cli check by isolating Command creation
1 parent 704ab92 commit 0f1dc36

File tree

1 file changed

+16
-43
lines changed

1 file changed

+16
-43
lines changed

src/utils/heroku.rs

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
use super::prompt::automated;
22

33
pub fn get_env_vars(project: &str) -> Vec<(String, String)> {
4-
if cfg!(windows) {
5-
check_heroku_cli_windows();
6-
} else {
7-
check_heroku_cli();
8-
}
4+
check_heroku_cli();
95

106
crate::utils::prompt::automated("Fetching env vars from heroku");
117

128
let heroku_vars = std::process::Command::new("heroku")
13-
// .current_dir(&dir)
149
.arg("config")
1510
.arg("-s")
1611
.args(&["-a", project])
@@ -29,45 +24,11 @@ pub fn get_env_vars(project: &str) -> Vec<(String, String)> {
2924
res
3025
}
3126

32-
// Checks if heroku-cli is installed, and then checks if user is logged in.
33-
// I was getting bogged down on building up the command according to the platform, so...
34-
fn check_heroku_cli_windows() {
35-
automated("Checking heroku-cli");
36-
37-
if std::process::Command::new("cmd")
38-
.args(&["/C", "heroku"])
39-
.stdout(std::process::Stdio::null())
40-
.status()
41-
.is_err()
42-
{
43-
eprintln!("heroku-cli not found. Please install and try again: https://devcenter.heroku.com/articles/heroku-cli");
44-
std::process::exit(1);
45-
}
46-
47-
if !std::process::Command::new("cmd")
48-
.args(&["/C", "heroku", "auth:whoami"])
49-
.status()
50-
.expect("Could not confirm login")
51-
.success()
52-
{
53-
let status = std::process::Command::new("cmd")
54-
.args(&["/C", "heroku", "login"])
55-
.spawn()
56-
.expect("Could not log in user.")
57-
.wait()
58-
.expect("??");
59-
60-
if !status.success() {
61-
std::process::exit(1);
62-
}
63-
}
64-
}
65-
6627
// Checks if heroku-cli is installed, and then checks if user is logged in.
6728
fn check_heroku_cli() {
6829
automated("Checking heroku-cli");
6930

70-
if std::process::Command::new("heroku")
31+
if heroku_cmd()
7132
.stdout(std::process::Stdio::null())
7233
.status()
7334
.is_err()
@@ -76,13 +37,13 @@ fn check_heroku_cli() {
7637
std::process::exit(1);
7738
}
7839

79-
if !std::process::Command::new("heroku")
40+
if !heroku_cmd()
8041
.arg("auth:whoami")
8142
.status()
8243
.expect("Could not confirm login")
8344
.success()
8445
{
85-
let status = std::process::Command::new("heroku")
46+
let status = heroku_cmd()
8647
.arg("login")
8748
.spawn()
8849
.expect("Could not log in user.")
@@ -94,3 +55,15 @@ fn check_heroku_cli() {
9455
}
9556
}
9657
}
58+
59+
#[cfg(windows)]
60+
fn heroku_cmd() -> std::process::Command {
61+
let mut cmd = std::process::Command::new("cmd");
62+
cmd.args(&["/C", "heroku"]);
63+
cmd
64+
}
65+
66+
#[cfg(not(windows))]
67+
fn heroku_cmd() -> std::process::Command {
68+
std::process::Command::new("heroku")
69+
}

0 commit comments

Comments
 (0)