forked from mas-cli/mas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mas-cli#689 from rgoldberg/684-region
Use MAS region instead of macOS region & add `mas region`
- Loading branch information
Showing
12 changed files
with
171 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Storefront.swift | ||
// mas | ||
// | ||
// Created by Ross Goldberg on 2024-12-29. | ||
// Copyright (c) 2024 mas-cli. All rights reserved. | ||
// | ||
|
||
import StoreKit | ||
|
||
enum Storefront { | ||
static var isoRegion: ISORegion? { | ||
if #available(macOS 10.15, *) { | ||
if let storefront = SKPaymentQueue.default().storefront { | ||
return findISORegion(forAlpha3Code: storefront.countryCode) | ||
} | ||
} | ||
|
||
guard let alpha2 = Locale.autoupdatingCurrent.regionCode else { | ||
return nil | ||
} | ||
|
||
return findISORegion(forAlpha2Code: alpha2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// Region.swift | ||
// mas | ||
// | ||
// Created by Ross Goldberg on 2024-12-29. | ||
// Copyright (c) 2024 mas-cli. All rights reserved. | ||
// | ||
|
||
import ArgumentParser | ||
|
||
extension MAS { | ||
/// Command which interacts with the current region for the Mac App Store. | ||
struct Region: ParsableCommand { | ||
static let configuration = CommandConfiguration( | ||
abstract: "Display the region of the Mac App Store" | ||
) | ||
|
||
/// Runs the command. | ||
func run() throws { | ||
guard let region = Storefront.isoRegion else { | ||
throw MASError.runtimeError("Could not obtain Mac App Store region") | ||
} | ||
|
||
print(region.alpha2) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// ISORegion.swift | ||
// mas | ||
// | ||
// Created by Ross Goldberg on 2024-12-29. | ||
// Copyright (c) 2024 mas-cli. All rights reserved. | ||
// | ||
|
||
import IsoCountryCodes | ||
|
||
func findISORegion(forAlpha2Code alpha2Code: String) -> ISORegion? { | ||
let alpha2Code = alpha2Code.uppercased() | ||
return IsoCountries.allCountries.first { $0.alpha2 == alpha2Code } | ||
} | ||
|
||
func findISORegion(forAlpha3Code alpha3Code: String) -> ISORegion? { | ||
let alpha3Code = alpha3Code.uppercased() | ||
return IsoCountries.allCountries.first { $0.alpha3 == alpha3Code } | ||
} | ||
|
||
// periphery:ignore | ||
protocol ISORegion { | ||
var name: String { get } | ||
var numeric: String { get } | ||
var alpha2: String { get } | ||
var alpha3: String { get } | ||
var calling: String { get } | ||
var currency: String { get } | ||
var continent: String { get } | ||
var flag: String? { get } | ||
var fractionDigits: Int { get } | ||
} | ||
|
||
extension IsoCountryInfo: ISORegion {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters