Skip to content

Commit

Permalink
fix: ensure version check message is displayed (#3358)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Dec 4, 2024
1 parent 33e88e3 commit 711f028
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/cli/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) });
Expand All @@ -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() })
}
Expand Down
14 changes: 7 additions & 7 deletions src/cli/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -59,11 +59,12 @@ pub static V: Lazy<Versioning> = 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<bool> {
#[cfg(unix)]
let mise_bin = "mise";
#[cfg(windows)]
Expand All @@ -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;
}
Expand All @@ -112,7 +112,7 @@ fn get_latest_version(duration: Duration) -> Option<String> {
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());
}
}
}
Expand Down

0 comments on commit 711f028

Please sign in to comment.