From e8362accad5a5291748d21c99f0d15e3468d416d Mon Sep 17 00:00:00 2001 From: wheatfox Date: Fri, 13 Dec 2024 17:43:54 +0800 Subject: [PATCH] Add better help texts for Error::ShellProgramNotFound add bun, deno, elixir and split the matching logic into different OS --- compiler-core/src/error.rs | 58 ++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/compiler-core/src/error.rs b/compiler-core/src/error.rs index 4ebc1f71d35..e2ea2d11397 100644 --- a/compiler-core/src/error.rs +++ b/compiler-core/src/error.rs @@ -1032,20 +1032,56 @@ https://gleam.run/getting-started/installing/", Documentation for installing rebar3 can be viewed here: https://gleam.run/getting-started/installing/", ), - _ => (), - } - match (program.as_str(), env::consts::OS) { - // TODO: Further suggestions for other OSes? - ("erl" | "erlc" | "escript", "macos") => text.push_str( - " -You can also install Erlang via homebrew using \"brew install erlang\"", - ), - ("rebar3", "macos") => text.push_str( + "bun" => text.push_str( " -You can also install rebar3 via homebrew using \"brew install rebar3\"", +Documentation for installing bun can be viewed here: +https://bun.sh/docs/installation/ +You may need to restart your shell after installing bun.", ), _ => (), - }; + } + match env::consts::OS { + "macos" => { + fn brew_install(program: &str) -> String { + format!("\nYou can install {} via homebrew: brew install {}", program, program) + } + match program.as_str() { + "erl" | "erlc" | "escript" => text.push_str(&brew_install("erlang")), + "rebar3" => text.push_str(&brew_install("rebar3")), + "deno" => text.push_str(&brew_install("deno")), + "elixir" => text.push_str(&brew_install("elixir")), + other => text.push_str(&wrap_format!(" +You might need to install {other} manually on your macOS." + )), + } + } + "linux" => { + if let Ok(distro) = std::fs::read_to_string("/etc/os-release") { + if distro.contains("ubuntu") || distro.contains("debian") { + text.push_str(&wrap_format!(" +You can try installing {program} using apt: \"sudo apt install {program}\". +If that doesn't work, you might need to install {program} manually." + )); + } else if distro.contains("fedora") || distro.contains("centos") { + text.push_str(&wrap_format!(" +You can try installing {program} using dnf: \"sudo dnf install {program}\". +If that doesn't work, you might need to install {program} manually." + )); + } else { + text.push_str(&wrap_format!(" +You might need to install {program} manually." + )); + } + } else { + text.push_str(&wrap_format!(" +Failed to determine your Linux distribution, please install {program} manually." + )); + } + } + _ => text.push_str(&format!(" +You might need to install {program} manually." + )), + } vec![Diagnostic { title: "Program not found".into(),