From d35f34e8f09219caea7731f8a063ac4e817087f1 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Sat, 14 Dec 2024 19:57:33 +0100 Subject: [PATCH] fix: gracefully handle unparsable versions & dont display metadata --- CHANGELOG.md | 1 + src/cli/commands/self_upgrade.rs | 18 +++++++++++------- src/cli/version.rs | 15 +++++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b936d6..7bf1535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Add Roblox types in linker modules even with no config generator script by @daimond113 +- Gracefully handle unparsable tag names when checking for updates & don't display build metadata by @daimond113 ### Changed - Remove lower bound limit of 3 characters for pesde package names by @daimond113 diff --git a/src/cli/commands/self_upgrade.rs b/src/cli/commands/self_upgrade.rs index 21f9c46..9117664 100644 --- a/src/cli/commands/self_upgrade.rs +++ b/src/cli/commands/self_upgrade.rs @@ -7,6 +7,7 @@ use crate::cli::{ use anyhow::Context; use clap::Args; use colored::Colorize; +use semver::BuildMetadata; #[derive(Debug, Args)] pub struct SelfUpgradeCommand { @@ -32,11 +33,17 @@ impl SelfUpgradeCommand { return Ok(()); } + let display_latest_version = { + let mut ver = latest_version.clone(); + // remove build metadata to make it more readable + ver.build = BuildMetadata::EMPTY; + ver.to_string().yellow().bold() + }; + if !inquire::prompt_confirmation(format!( - "are you sure you want to upgrade {} from {} to {}?", + "are you sure you want to upgrade {} from {} to {display_latest_version}?", env!("CARGO_BIN_NAME").cyan(), - current_version().to_string().yellow().bold(), - latest_version.to_string().yellow().bold() + env!("CARGO_PKG_VERSION").yellow().bold() ))? { println!("cancelled upgrade"); return Ok(()); @@ -47,10 +54,7 @@ impl SelfUpgradeCommand { .unwrap(); update_bin_exe(&path).await?; - println!( - "upgraded to version {}!", - latest_version.to_string().yellow().bold() - ); + println!("upgraded to version {display_latest_version}!",); Ok(()) } diff --git a/src/cli/version.rs b/src/cli/version.rs index 858fc9f..3c0494b 100644 --- a/src/cli/version.rs +++ b/src/cli/version.rs @@ -59,7 +59,7 @@ pub async fn get_latest_remote_version(reqwest: &reqwest::Client) -> anyhow::Res releases .into_iter() - .map(|release| Version::parse(release.tag_name.trim_start_matches('v')).unwrap()) + .filter_map(|release| Version::parse(release.tag_name.trim_start_matches('v')).ok()) .max() .context("failed to find latest version") } @@ -89,11 +89,18 @@ pub async fn check_for_updates(reqwest: &reqwest::Client) -> anyhow::Result<()> if version > current_version { let name = env!("CARGO_BIN_NAME"); - let changelog = format!("{}/releases/tag/v{version}", env!("CARGO_PKG_REPOSITORY"),); + let changelog = format!("{}/releases/tag/v{version}", env!("CARGO_PKG_REPOSITORY")); + + let display_version = { + let mut ver = version.clone(); + // remove build metadata to make it more readable + ver.build = semver::BuildMetadata::EMPTY; + ver.to_string() + }; let unformatted_messages = [ "".to_string(), - format!("update available! {current_version} → {version}"), + format!("update available! {current_version} → {display_version}"), format!("changelog: {changelog}"), format!("run `{name} self-upgrade` to upgrade"), "".to_string(), @@ -113,7 +120,7 @@ pub async fn check_for_updates(reqwest: &reqwest::Client) -> anyhow::Result<()> format!( "update available! {} → {}", current_version.to_string().red(), - version.to_string().green() + display_version.green() ), format!("changelog: {}", changelog.blue()), format!(