Sort search results by name and version

This commit is contained in:
2024-11-21 10:58:36 +11:00
parent c239b8e424
commit 8a339d6116
3 changed files with 336 additions and 1 deletions

View File

@ -50,10 +50,24 @@ struct DpkSearchCommand: AsyncParsableCommand {
throw .failure
}
var results = [ApkIndexPackage]()
for package in index.packages {
if match.match(package.name) || (!self.nameOnly && match.match(package.packageDescription)) {
print(package.shortDescription)
results.append(package)
}
}
results.sort { lhs, rhs in
switch lhs.name.localizedCaseInsensitiveCompare(rhs.name) {
case .orderedSame:
ApkVersionCompare.compare(lhs.version, rhs.version) == .greater
case .orderedDescending: false
case .orderedAscending: true
}
}
for package in results {
print(package.shortDescription)
}
}
}