From 711f02899d1b2403fbf0b3c3ffcd55e8ec18312d Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:52:51 -0600 Subject: [PATCH] fix: ensure version check message is displayed (#3358) --- src/cli/doctor.rs | 1 + src/cli/mod.rs | 6 +++++- src/cli/version.rs | 14 +++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cli/doctor.rs b/src/cli/doctor.rs index 91457ec6bd..1845af01be 100644 --- a/src/cli/doctor.rs +++ b/src/cli/doctor.rs @@ -54,6 +54,7 @@ impl Doctor { self.analyze_settings()?; if let Some(latest) = version::check_for_new_version(duration::HOURLY) { + version::show_latest(); self.errors.push(format!( "new mise version {latest} available, currently on {}", *version::V diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 0f7141a199..a1df93f90c 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -276,7 +276,7 @@ impl Cli { crate::env::ARGS.write().unwrap().clone_from(args); measure!("hande_shim", { shims::handle_shim() })?; ctrlc::init(); - version::print_version_if_requested(args)?; + let print_version = version::print_version_if_requested(args)?; let cli = measure!("pre_settings", { Self::pre_settings(args) })?; measure!("add_cli_matches", { Settings::add_cli_matches(&cli) }); @@ -290,6 +290,10 @@ impl Cli { } debug!("ARGS: {}", &args.join(" ")); + if print_version { + version::show_latest(); + exit(0); + } let cmd = cli.get_command()?; measure!("run {cmd}", { cmd.run() }) } diff --git a/src/cli/version.rs b/src/cli/version.rs index 3266f254b5..d46afbdcbd 100644 --- a/src/cli/version.rs +++ b/src/cli/version.rs @@ -10,7 +10,7 @@ use crate::cli::self_update::SelfUpdate; #[cfg(not(test))] use crate::config::Settings; use crate::file::modified_duration; -use crate::{dirs, duration, env, exit, file}; +use crate::{dirs, duration, env, file}; /// Display the version of mise /// @@ -59,11 +59,12 @@ pub static V: Lazy = Lazy::new(|| Versioning::new(env!("CARGO_PKG_VE impl Version { pub fn run(self) -> Result<()> { show_version()?; + show_latest(); Ok(()) } } -pub fn print_version_if_requested(args: &[String]) -> std::io::Result<()> { +pub fn print_version_if_requested(args: &[String]) -> std::io::Result { #[cfg(unix)] let mise_bin = "mise"; #[cfg(windows)] @@ -72,20 +73,19 @@ pub fn print_version_if_requested(args: &[String]) -> std::io::Result<()> { let cmd = &args[1].to_lowercase(); if cmd == "version" || cmd == "-v" || cmd == "--version" { show_version()?; - exit(0); + return Ok(true); } } debug!("Version: {}", *VERSION); - Ok(()) + Ok(false) } fn show_version() -> std::io::Result<()> { miseprintln!("{}", *VERSION); - show_latest(); Ok(()) } -fn show_latest() { +pub fn show_latest() { if ci_info::is_ci() && !cfg!(test) { return; } @@ -112,7 +112,7 @@ fn get_latest_version(duration: Duration) -> Option { if let Ok(metadata) = modified_duration(&version_file_path) { if metadata < duration { if let Ok(version) = file::read_to_string(&version_file_path) { - return Some(version); + return Some(version.trim().to_string()); } } }