fix: gracefully handle unparsable versions & dont display metadata

This commit is contained in:
daimond113 2024-12-14 19:57:33 +01:00
parent 9ee75ec9c9
commit d35f34e8f0
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
3 changed files with 23 additions and 11 deletions

View file

@ -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

View file

@ -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(())
}

View file

@ -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!(