mirror of
https://github.com/GayPizzaSpecifications/darwin-apk.git
synced 2025-08-04 05:51:31 +00:00
Sort search results by name and version
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user