Print update warning correctly formatted

This commit is contained in:
binarybaron 2022-11-25 13:58:44 +01:00
parent 0e242110bd
commit 52871c9fc8

View File

@ -9,19 +9,18 @@ pub enum Version {
} }
/// Check the latest release from GitHub API. /// Check the latest release from GitHub API.
pub async fn check_latest_version(current: &str) -> anyhow::Result<Version> { pub async fn check_latest_version(current_version: &str) -> anyhow::Result<Version> {
let response = reqwest::get(LATEST_RELEASE_URL).await?; let response = reqwest::get(LATEST_RELEASE_URL).await?;
let e = "Failed to get latest release."; let e = "Failed to get latest release.";
let url = response.url(); let download_url = response.url();
let segments = url.path_segments().ok_or_else(|| anyhow!(e))?; let segments = download_url.path_segments().ok_or_else(|| anyhow!(e))?;
let latest = segments.last().ok_or_else(|| anyhow!(e))?; let latest_version = segments.last().ok_or_else(|| anyhow!(e))?;
let result = if is_latest_version(current, latest) { let result = if is_latest_version(current_version, latest_version) {
Version::Current Version::Current
} else { } else {
println!( tracing::warn!(%current_version, %latest_version, %download_url,
"You are not on the latest version: {} is available. \n{}", "You are not on the latest version",
latest, url
); );
Version::Available Version::Available
}; };