diff --git a/src/cortex-cli/src/upgrade_cmd.rs b/src/cortex-cli/src/upgrade_cmd.rs index a59b0116..40fe7204 100644 --- a/src/cortex-cli/src/upgrade_cmd.rs +++ b/src/cortex-cli/src/upgrade_cmd.rs @@ -99,8 +99,8 @@ impl UpgradeCli { Ok(info) => Some(info), Err(e) => { // Check if user asked for current version (Issue #1968) - let normalized_version = version.trim_start_matches('v'); - let normalized_current = CLI_VERSION.trim_start_matches('v'); + let normalized_version = normalize_version_input(version); + let normalized_current = normalize_version_input(CLI_VERSION); if normalized_version == normalized_current { println!("\n✓ Already on version v{}. No action needed.", CLI_VERSION); return Ok(()); @@ -217,8 +217,9 @@ impl UpgradeCli { /// Check for a specific version async fn check_specific_version(manager: &UpdateManager, version: &str) -> Result { let client = cortex_update::CortexSoftwareClient::new(); + let normalized_version = normalize_version_input(version); let release = client - .get_release(version) + .get_release(normalized_version) .await .context(format!("Version {} not found", version))?; @@ -238,6 +239,10 @@ async fn check_specific_version(manager: &UpdateManager, version: &str) -> Resul }) } +fn normalize_version_input(version: &str) -> &str { + version.trim_start_matches(['v', 'V']) +} + /// Perform the actual upgrade async fn perform_upgrade(manager: &UpdateManager, info: &UpdateInfo) -> Result<()> { println!("\nDownloading v{}...", info.latest_version); @@ -492,4 +497,11 @@ mod tests { assert_eq!(semver_compare("1.0.0", "2.0.0"), -1); assert_eq!(semver_compare("v1.0.0", "1.0.0"), 0); } + + #[test] + fn test_normalize_version_input() { + assert_eq!(normalize_version_input("0.0.7"), "0.0.7"); + assert_eq!(normalize_version_input("v0.0.7"), "0.0.7"); + assert_eq!(normalize_version_input("V0.0.7"), "0.0.7"); + } }