From 733645a7ed5a8026a696a52a4ae19622a4326fc6 Mon Sep 17 00:00:00 2001 From: LinkIsGrim <69561145+LinkIsGrim@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:36:55 -0300 Subject: [PATCH 1/2] bin: show update script for linux/macos --- bin/src/lib.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bin/src/lib.rs b/bin/src/lib.rs index a653c593..09593185 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -112,10 +112,27 @@ pub fn execute(cli: &Cli) -> Result<(), Error> { 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" - ); + 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() + ), + _ => ( + "HEMTT is installed in home directory, run `curl -sSf https://hemtt.dev/install.sh | sh` to update", { + let mut default = dirs::home_dir().expect("home directory exists"); + if os != "macos" { + default = default.join(".local") + }; + + default.join("bin").display().to_string() + } + ), + }; + + if path.display().to_string().contains(&filter) { + info!(message) } } } From 3f1250f32757311c93c71705e97d13441cd2935f Mon Sep 17 00:00:00 2001 From: Brett Mayson Date: Thu, 19 Dec 2024 23:28:06 +0000 Subject: [PATCH 2/2] break out, refactor a bit --- bin/src/lib.rs | 78 +++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/bin/src/lib.rs b/bin/src/lib.rs index 09593185..365a24d9 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -106,42 +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()); - 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() - ), - _ => ( - "HEMTT is installed in home directory, run `curl -sSf https://hemtt.dev/install.sh | sh` to update", { - let mut default = dirs::home_dir().expect("home directory exists"); - if os != "macos" { - default = default.join(".local") - }; - - default.join("bin").display().to_string() - } - ), - }; - - if path.display().to_string().contains(&filter) { - info!(message) - } - } - } - Err(e) => { - error!("Failed to check for updates: {e}"); - } - _ => {} - } - } + check_for_update(); trace!("version: {}", env!("HEMTT_VERSION")); trace!("platform: {}", std::env::consts::OS); @@ -236,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 {