From b1df2c06cda10375d6c295d84ea148df6f6b02d6 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:48:16 -0300 Subject: [PATCH] bin: show update script for linux/macos (#853) * bin: show update script for linux/macos * break out, refactor a bit --------- Co-authored-by: Brett Mayson --- bin/src/lib.rs | 61 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/bin/src/lib.rs b/bin/src/lib.rs index a653c593..365a24d9 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -106,25 +106,7 @@ pub fn execute(cli: &Cli) -> Result<(), Error> { std::env::set_current_dir(dir).expect("Failed to set current directory"); } - if !is_ci() { - match update::check() { - Ok(Some(version)) => { - info!("HEMTT {version} is available, please update"); - if let Ok(path) = std::env::current_exe() { - trace!("HEMTT is installed at: {}", path.display()); - if path.display().to_string().contains("\\Winget\\") { - info!( - "HEMTT is installed via winget, run `winget upgrade hemtt` to update" - ); - } - } - } - Err(e) => { - error!("Failed to check for updates: {e}"); - } - _ => {} - } - } + check_for_update(); trace!("version: {}", env!("HEMTT_VERSION")); trace!("platform: {}", std::env::consts::OS); @@ -219,6 +201,47 @@ pub fn is_ci() -> bool { false } +fn check_for_update() { + if is_ci() { + return; + } + match update::check() { + Ok(Some(version)) => { + info!("HEMTT {version} is available, please update"); + } + Err(e) => { + error!("Failed to check for updates: {e}"); + return; + } + _ => return, + } + let Ok(path) = std::env::current_exe() else { + return; + }; + trace!("HEMTT is installed at: {}", path.display()); + let os = std::env::consts::OS; + let (message, filter) = match os { + "windows" => ( + "HEMTT is installed via winget, run `winget upgrade hemtt` to update", + "\\Winget\\".to_string() + ), + "linux" | "macos" => ( + "HEMTT is installed in home directory, run `curl -sSf https://hemtt.dev/install.sh | sh` to update", { + let mut home = dirs::home_dir().expect("home directory exists"); + if os == "linux" { + home = home.join(".local"); + }; + home.join("bin").display().to_string() + } + ), + _ => return, + }; + + if path.display().to_string().contains(&filter) { + info!(message); + } +} + #[derive(clap::ValueEnum, Clone, Default, Debug, serde::Serialize)] #[serde(rename_all = "kebab-case")] pub enum TableFormat {