commands/update: use flexver for version sorting

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I4e1cd3247e74247cbde65391510bd3586a6a6964
This commit is contained in:
raf 2026-04-18 21:29:24 +03:00
commit 2c4058b54a
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -7,6 +7,7 @@ use crate::{
error::{MultiError, PakkerError},
model::{Config, LockFile, UpdateStrategy},
ui_utils::{prompt_select, prompt_typo_suggestion, prompt_yes_no},
utils::FlexVer,
};
pub async fn execute(
@ -141,6 +142,15 @@ pub async fn execute(
&& !updated_project.files.is_empty()
&& let Some(old_file) = lockfile.projects[idx].files.first()
{
// Sort files by FlexVer if that strategy is set
if old_project.update_strategy == UpdateStrategy::FlexVer {
updated_project.files.sort_by(|a, b| {
// Use FlexVer for comparison - b.cmp(a) gives descending order
// (newest first)
FlexVer(&b.file_name).cmp(&FlexVer(&a.file_name))
});
}
// Clone data needed for comparisons to avoid borrow issues
let new_file_id = updated_project.files.first().unwrap().id.clone();
let new_file_name =