Skip to content

Commit 1d1ada0

Browse files
committed
fix(cli): normalize upgrade version prefix
1 parent 7954d02 commit 1d1ada0

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/cortex-cli/src/upgrade_cmd.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ impl UpgradeCli {
9999
Ok(info) => Some(info),
100100
Err(e) => {
101101
// Check if user asked for current version (Issue #1968)
102-
let normalized_version = version.trim_start_matches('v');
103-
let normalized_current = CLI_VERSION.trim_start_matches('v');
102+
let normalized_version = normalize_version_input(version);
103+
let normalized_current = normalize_version_input(CLI_VERSION);
104104
if normalized_version == normalized_current {
105105
println!("\n✓ Already on version v{}. No action needed.", CLI_VERSION);
106106
return Ok(());
@@ -217,8 +217,9 @@ impl UpgradeCli {
217217
/// Check for a specific version
218218
async fn check_specific_version(manager: &UpdateManager, version: &str) -> Result<UpdateInfo> {
219219
let client = cortex_update::CortexSoftwareClient::new();
220+
let normalized_version = normalize_version_input(version);
220221
let release = client
221-
.get_release(version)
222+
.get_release(normalized_version)
222223
.await
223224
.context(format!("Version {} not found", version))?;
224225

@@ -238,6 +239,10 @@ async fn check_specific_version(manager: &UpdateManager, version: &str) -> Resul
238239
})
239240
}
240241

242+
fn normalize_version_input(version: &str) -> &str {
243+
version.trim_start_matches(['v', 'V'])
244+
}
245+
241246
/// Perform the actual upgrade
242247
async fn perform_upgrade(manager: &UpdateManager, info: &UpdateInfo) -> Result<()> {
243248
println!("\nDownloading v{}...", info.latest_version);
@@ -492,4 +497,11 @@ mod tests {
492497
assert_eq!(semver_compare("1.0.0", "2.0.0"), -1);
493498
assert_eq!(semver_compare("v1.0.0", "1.0.0"), 0);
494499
}
500+
501+
#[test]
502+
fn test_normalize_version_input() {
503+
assert_eq!(normalize_version_input("0.0.7"), "0.0.7");
504+
assert_eq!(normalize_version_input("v0.0.7"), "0.0.7");
505+
assert_eq!(normalize_version_input("V0.0.7"), "0.0.7");
506+
}
495507
}

0 commit comments

Comments
 (0)