Skip to content

Commit

Permalink
Fix exact matching of search string
Browse files Browse the repository at this point in the history
  • Loading branch information
ninxsoft committed Sep 27, 2023
1 parent 83f1a2d commit 13a2dce
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Mist/Commands/Download/DownloadFirmwareOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct DownloadFirmwareOptions: ParsableArguments {
macOS Big Sur │ 11.x │ 20xyz
Note: Specifying a macOS name will assume the latest version and build of that particular macOS.
Note: Specifying a macOS version will assume the latest build of that particular macOS.
Note: Specifying a macOS version will look for an exact match, otherwise assume the latest build of that particular macOS.
""")
var searchString: String

Expand Down
2 changes: 1 addition & 1 deletion Mist/Commands/Download/DownloadInstallerOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct DownloadInstallerOptions: ParsableArguments {
Mac OS X Lion │ 10.7.5 │ 11xyz
Note: Specifying a macOS name will assume the latest version and build of that particular macOS.
Note: Specifying a macOS version will assume the latest build of that particular macOS.
Note: Specifying a macOS version will look for an exact match, otherwise assume the latest build of that particular macOS.
""")
var searchString: String

Expand Down
2 changes: 1 addition & 1 deletion Mist/Commands/List/ListFirmwareOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct ListFirmwareOptions: ParsableArguments {
macOS Big Sur │ 11.x │ 20xyz
Note: Specifying a macOS name will assume the latest version and build of that particular macOS.
Note: Specifying a macOS version will assume the latest build of that particular macOS.
Note: Specifying a macOS version will look for an exact match, otherwise assume the latest build of that particular macOS.
""")
var searchString: String?

Expand Down
2 changes: 1 addition & 1 deletion Mist/Commands/List/ListInstallerOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ListInstallerOptions: ParsableArguments {
Mac OS X Lion │ 10.7.5 │ 11xyz
Note: Specifying a macOS name will assume the latest version and build of that particular macOS.
Note: Specifying a macOS version will assume the latest build of that particular macOS.
Note: Specifying a macOS version will look for an exact match, otherwise assume the latest build of that particular macOS.
""")
var searchString: String?

Expand Down
10 changes: 6 additions & 4 deletions Mist/Helpers/HTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ struct HTTP {
static func firmware(from firmwares: [Firmware], searchString: String) -> Firmware? {
let searchString: String = searchString.lowercased().replacingOccurrences(of: "macos ", with: "")
let filteredFirmwaresByName: [Firmware] = firmwares.filter { $0.name.lowercased().replacingOccurrences(of: "macos ", with: "").contains(searchString) }
let filteredFirmwaresByVersion: [Firmware] = firmwares.filter { searchString.contains(".") ? $0.version.lowercased() == searchString : $0.version.lowercased().starts(with: searchString) }
let filteredFirmwaresByVersionExact: [Firmware] = firmwares.filter { $0.version.lowercased() == searchString }
let filteredFirmwaresByVersionStartsWith: [Firmware] = firmwares.filter { $0.version.lowercased().starts(with: searchString) }
let filteredFirmwaresByBuild: [Firmware] = firmwares.filter { $0.build.lowercased().starts(with: searchString) }
return filteredFirmwaresByName.first ?? filteredFirmwaresByVersion.first ?? filteredFirmwaresByBuild.first
return filteredFirmwaresByName.first ?? filteredFirmwaresByVersionExact.first ?? filteredFirmwaresByVersionStartsWith.first ?? filteredFirmwaresByBuild.first
}

/// Retrieves macOS Firmware downloads matching the provided search string.
Expand Down Expand Up @@ -392,9 +393,10 @@ struct HTTP {
static func installer(from installers: [Installer], searchString: String) -> Installer? {
let searchString: String = searchString.lowercased().replacingOccurrences(of: "macos ", with: "")
let filteredInstallersByName: [Installer] = installers.filter { $0.name.lowercased().replacingOccurrences(of: "macos ", with: "").contains(searchString) }
let filteredInstallersByVersion: [Installer] = installers.filter { searchString.contains(".") ? $0.version.lowercased() == searchString : $0.version.lowercased().starts(with: searchString) }
let filteredInstallersByVersionExact: [Installer] = installers.filter { $0.version.lowercased() == searchString }
let filteredInstallersByVersionStartsWith: [Installer] = installers.filter { $0.version.lowercased().starts(with: searchString) }
let filteredInstallersByBuild: [Installer] = installers.filter { $0.build.lowercased().starts(with: searchString) }
return filteredInstallersByName.first ?? filteredInstallersByVersion.first ?? filteredInstallersByBuild.first
return filteredInstallersByName.first ?? filteredInstallersByVersionExact.first ?? filteredInstallersByVersionStartsWith.first ?? filteredInstallersByBuild.first
}

/// Retrieves macOS Installer downloads matching the provided search string.
Expand Down

0 comments on commit 13a2dce

Please sign in to comment.