mirror of
https://github.com/mas-cli/mas
synced 2024-11-23 20:13:19 +00:00
Use formattedPrice
instead of price
.
Improve price output. Partial #597 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
This commit is contained in:
parent
12832f293d
commit
1b4c97f652
8 changed files with 891 additions and 3349 deletions
|
@ -18,7 +18,7 @@ enum AppInfoFormatter {
|
||||||
let headline = [
|
let headline = [
|
||||||
"\(app.trackName)",
|
"\(app.trackName)",
|
||||||
"\(app.version)",
|
"\(app.version)",
|
||||||
"[\(app.price ?? 0)]",
|
"[\(app.formattedPrice)]",
|
||||||
]
|
]
|
||||||
.joined(separator: " ")
|
.joined(separator: " ")
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,11 @@ enum SearchResultFormatter {
|
||||||
let appID = result.trackId
|
let appID = result.trackId
|
||||||
let appName = result.trackName.padding(toLength: maxLength, withPad: " ", startingAt: 0)
|
let appName = result.trackName.padding(toLength: maxLength, withPad: " ", startingAt: 0)
|
||||||
let version = result.version
|
let version = result.version
|
||||||
let price = result.price ?? 0.0
|
|
||||||
|
|
||||||
if includePrice {
|
if includePrice {
|
||||||
output += String(format: "%12lu %@ $%5.2f (%@)\n", appID, appName, price, version)
|
output += String(format: "%12lu %@ (%@) %@\n", appID, appName, version, result.formattedPrice)
|
||||||
} else {
|
} else {
|
||||||
output += String(format: "%12lu %@ (%@)\n", appID, appName, version)
|
output += String(format: "%12lu %@ (%@)\n", appID, appName, version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ struct SearchResult: Decodable {
|
||||||
var bundleId: String
|
var bundleId: String
|
||||||
var currentVersionReleaseDate: String
|
var currentVersionReleaseDate: String
|
||||||
var fileSizeBytes: String?
|
var fileSizeBytes: String?
|
||||||
|
var formattedPrice: String
|
||||||
var minimumOsVersion: String
|
var minimumOsVersion: String
|
||||||
var price: Double?
|
var price: Double?
|
||||||
var sellerName: String
|
var sellerName: String
|
||||||
|
@ -23,6 +24,7 @@ struct SearchResult: Decodable {
|
||||||
bundleId: String = "",
|
bundleId: String = "",
|
||||||
currentVersionReleaseDate: String = "",
|
currentVersionReleaseDate: String = "",
|
||||||
fileSizeBytes: String = "0",
|
fileSizeBytes: String = "0",
|
||||||
|
formattedPrice: String = "0",
|
||||||
minimumOsVersion: String = "",
|
minimumOsVersion: String = "",
|
||||||
price: Double = 0.0,
|
price: Double = 0.0,
|
||||||
sellerName: String = "",
|
sellerName: String = "",
|
||||||
|
@ -35,6 +37,7 @@ struct SearchResult: Decodable {
|
||||||
self.bundleId = bundleId
|
self.bundleId = bundleId
|
||||||
self.currentVersionReleaseDate = currentVersionReleaseDate
|
self.currentVersionReleaseDate = currentVersionReleaseDate
|
||||||
self.fileSizeBytes = fileSizeBytes
|
self.fileSizeBytes = fileSizeBytes
|
||||||
|
self.formattedPrice = formattedPrice
|
||||||
self.minimumOsVersion = minimumOsVersion
|
self.minimumOsVersion = minimumOsVersion
|
||||||
self.price = price
|
self.price = price
|
||||||
self.sellerName = sellerName
|
self.sellerName = sellerName
|
||||||
|
|
|
@ -39,8 +39,8 @@ public class InfoSpec: QuickSpec {
|
||||||
let mockResult = SearchResult(
|
let mockResult = SearchResult(
|
||||||
currentVersionReleaseDate: "2019-01-07T18:53:13Z",
|
currentVersionReleaseDate: "2019-01-07T18:53:13Z",
|
||||||
fileSizeBytes: "1024",
|
fileSizeBytes: "1024",
|
||||||
|
formattedPrice: "$2.00",
|
||||||
minimumOsVersion: "10.14",
|
minimumOsVersion: "10.14",
|
||||||
price: 2.0,
|
|
||||||
sellerName: "Awesome Dev",
|
sellerName: "Awesome Dev",
|
||||||
trackId: 1111,
|
trackId: 1111,
|
||||||
trackName: "Awesome App",
|
trackName: "Awesome App",
|
||||||
|
@ -54,7 +54,7 @@ public class InfoSpec: QuickSpec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
== """
|
== """
|
||||||
Awesome App 1.0 [2.0]
|
Awesome App 1.0 [$2.00]
|
||||||
By: Awesome Dev
|
By: Awesome Dev
|
||||||
Released: 2019-01-07
|
Released: 2019-01-07
|
||||||
Minimum OS: 10.14
|
Minimum OS: 10.14
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class SearchSpec: QuickSpec {
|
||||||
try MAS.Search.parse(["slack"]).run(searcher: searcher)
|
try MAS.Search.parse(["slack"]).run(searcher: searcher)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
== " 1111 slack (0.0)\n"
|
== " 1111 slack (0.0)\n"
|
||||||
}
|
}
|
||||||
it("fails when searching for nonexistent app") {
|
it("fails when searching for nonexistent app") {
|
||||||
expect {
|
expect {
|
||||||
|
|
|
@ -29,57 +29,57 @@ public class SearchResultFormatterSpec: QuickSpec {
|
||||||
}
|
}
|
||||||
it("can format a single result") {
|
it("can format a single result") {
|
||||||
let result = SearchResult(
|
let result = SearchResult(
|
||||||
price: 9.87,
|
formattedPrice: "$9.87",
|
||||||
trackId: 12345,
|
trackId: 12345,
|
||||||
trackName: "Awesome App",
|
trackName: "Awesome App",
|
||||||
version: "19.2.1"
|
version: "19.2.1"
|
||||||
)
|
)
|
||||||
expect(format([result], false)) == " 12345 Awesome App (19.2.1)"
|
expect(format([result], false)) == " 12345 Awesome App (19.2.1)"
|
||||||
}
|
}
|
||||||
it("can format a single result with price") {
|
it("can format a single result with price") {
|
||||||
let result = SearchResult(
|
let result = SearchResult(
|
||||||
price: 9.87,
|
formattedPrice: "$9.87",
|
||||||
trackId: 12345,
|
trackId: 12345,
|
||||||
trackName: "Awesome App",
|
trackName: "Awesome App",
|
||||||
version: "19.2.1"
|
version: "19.2.1"
|
||||||
)
|
)
|
||||||
expect(format([result], true)) == " 12345 Awesome App $ 9.87 (19.2.1)"
|
expect(format([result], true)) == " 12345 Awesome App (19.2.1) $9.87"
|
||||||
}
|
}
|
||||||
it("can format a two results") {
|
it("can format a two results") {
|
||||||
results = [
|
results = [
|
||||||
SearchResult(
|
SearchResult(
|
||||||
price: 9.87,
|
formattedPrice: "$9.87",
|
||||||
trackId: 12345,
|
trackId: 12345,
|
||||||
trackName: "Awesome App",
|
trackName: "Awesome App",
|
||||||
version: "19.2.1"
|
version: "19.2.1"
|
||||||
),
|
),
|
||||||
SearchResult(
|
SearchResult(
|
||||||
price: 0.01,
|
formattedPrice: "$0.01",
|
||||||
trackId: 67890,
|
trackId: 67890,
|
||||||
trackName: "Even Better App",
|
trackName: "Even Better App",
|
||||||
version: "1.2.0"
|
version: "1.2.0"
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
expect(format(results, false))
|
expect(format(results, false))
|
||||||
== " 12345 Awesome App (19.2.1)\n 67890 Even Better App (1.2.0)"
|
== " 12345 Awesome App (19.2.1)\n 67890 Even Better App (1.2.0)"
|
||||||
}
|
}
|
||||||
it("can format a two results with prices") {
|
it("can format a two results with prices") {
|
||||||
results = [
|
results = [
|
||||||
SearchResult(
|
SearchResult(
|
||||||
price: 9.87,
|
formattedPrice: "$9.87",
|
||||||
trackId: 12345,
|
trackId: 12345,
|
||||||
trackName: "Awesome App",
|
trackName: "Awesome App",
|
||||||
version: "19.2.1"
|
version: "19.2.1"
|
||||||
),
|
),
|
||||||
SearchResult(
|
SearchResult(
|
||||||
price: 0.01,
|
formattedPrice: "$0.01",
|
||||||
trackId: 67890,
|
trackId: 67890,
|
||||||
trackName: "Even Better App",
|
trackName: "Even Better App",
|
||||||
version: "1.2.0"
|
version: "1.2.0"
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
expect(format(results, true))
|
expect(format(results, true))
|
||||||
== " 12345 Awesome App $ 9.87 (19.2.1)\n 67890 Even Better App $ 0.01 (1.2.0)"
|
== " 12345 Awesome App (19.2.1) $9.87\n 67890 Even Better App (1.2.0) $0.01"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
"trackName": "Things That Go Bump",
|
"trackName": "Things That Go Bump",
|
||||||
"trackId": 1472954003,
|
"trackId": 1472954003,
|
||||||
"sellerName": "Tinybop Inc.",
|
"sellerName": "Tinybop Inc.",
|
||||||
|
"price": 0.99,
|
||||||
|
"formattedPrice": "$0.99",
|
||||||
"releaseNotes": "* BOOM *, this is a BIG update. The house spawns a game room, complete with video games you can ENTER INTO. It's fun and a little bit weird! Try it! \n»-(¯`·.·´¯)->",
|
"releaseNotes": "* BOOM *, this is a BIG update. The house spawns a game room, complete with video games you can ENTER INTO. It's fun and a little bit weird! Try it! \n»-(¯`·.·´¯)->",
|
||||||
"primaryGenreId": 6014,
|
"primaryGenreId": 6014,
|
||||||
"primaryGenreName": "Games",
|
"primaryGenreName": "Games",
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue