8000 Use `formattedPrice` for prices by rgoldberg · Pull Request #601 · mas-cli/mas · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use formattedPrice for prices #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/mas/Formatters/AppInfoFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum AppInfoFormatter {
let headline = [
"\(app.trackName)",
"\(app.version)",
"[\(app.price ?? 0)]",
"[\(app.formattedPrice)]",
]
.joined(separator: " ")

Expand All @@ -27,7 +27,7 @@ enum AppInfoFormatter {
"By: \(app.sellerName)",
"Released: \(humanReadableDate(app.currentVersionReleaseDate))",
"Minimum OS: \(app.minimumOsVersion)",
"Size: \(humanReadableSize(app.fileSizeBytes ?? "0"))",
"Size: \(humanReadableSize(app.fileSizeBytes))",
"From: \(app.trackViewUrl)",
]
.joined(separator: "\n")
Expand Down
5 changes: 2 additions & 3 deletions Sources/mas/Formatters/SearchResultFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ enum SearchResultFormatter {
let appID = result.trackId
let appName = result.trackName.padding(toLength: maxLength, withPad: " ", startingAt: 0)
let version = result.version
let price = result.price ?? 0.0

if includePrice {
output += String(format: "%12lu %@ $%5.2f (%@)\n", appID, appName, price, version)
output += String(format: "%12lu %@ (%@) %@\n", appID, appName, version, result.formattedPrice)
} else {
output += String(format: "%12lu %@ (%@)\n", appID, appName, version)
output += String(format: "%12lu %@ (%@)\n", appID, appName, version)
}
}

Expand Down
7 changes: 5 additions & 2 deletions Sources/mas/Models/SearchResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
struct SearchResult: Decodable {
var bundleId: String
var currentVersionReleaseDate: String
var fileSizeBytes: String?
var fileSizeBytes: String
var formattedPrice: String
var minimumOsVersion: String
var price: Double?
var price: Double
var sellerName: String
var sellerUrl: String?
var trackId: AppID
Expand All @@ -23,6 +24,7 @@ struct SearchResult: Decodable {
bundleId: String = "",
currentVersionReleaseDate: String = "",
fileSizeBytes: String = "0",
formattedPrice: String = "0",
minimumOsVersion: String = "",
price: Double = 0.0,
sellerName: String = "",
Expand All @@ -35,6 +37,7 @@ struct SearchResult: Decodable {
self.bundleId = bundleId
self.currentVersionReleaseDate = currentVersionReleaseDate
self.fileSizeBytes = fileSizeBytes
self.formattedPrice = formattedPrice
self.minimumOsVersion = minimumOsVersion
self.price = price
self.sellerName = sellerName
Expand Down
4 changes: 2 additions & 2 deletions Tests/masTests/Commands/InfoSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class InfoSpec: QuickSpec {
let mockResult = SearchResult(
currentVersionReleaseDate: "2019-01-07T18:53:13Z",
fileSizeBytes: "1024",
formattedPrice: "$2.00",
minimumOsVersion: "10.14",
price: 2.0,
sellerName: "Awesome Dev",
trackId: 1111,
trackName: "Awesome App",
Expand All @@ -54,7 +54,7 @@ public class InfoSpec: QuickSpec {
}
}
== """
Awesome App 1.0 [2.0]
Awesome App 1.0 [$2.00]
By: Awesome Dev
Released: 2019-01-07
Minimum OS: 10.14
Expand Down
2 changes: 1 addition & 1 deletion Tests/masTests/Commands/SearchSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SearchSpec: QuickSpec {
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") {
expect {
Expand Down
20 changes: 10 additions & 10 deletions Tests/masTests/Formatters/SearchResultFormatterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,57 +29,57 @@ public class SearchResultFormatterSpec: QuickSpec {
}
it("can format a single result") {
let result = SearchResult(
price: 9.87,
formattedPrice: "$9.87",
trackId: 12345,
trackName: "Awesome App",
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") {
let result = SearchResult(
price: 9.87,
formattedPrice: "$9.87",
trackId: 12345,
trackName: "Awesome App",
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") {
results = [
SearchResult(
price: 9.87,
formattedPrice: "$9.87",
trackId: 12345,
trackName: "Awesome App",
version: "19.2.1"
),
SearchResult(
price: 0.01,
formattedPrice: "$0.01",
trackId: 67890,
trackName: "Even Better App",
version: "1.2.0"
),
]
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") {
results = [
SearchResult(
price: 9.87,
formattedPrice: "$9.87",
trackId: 12345,
trackName: "Awesome App",
version: "19.2.1"
),
SearchResult(
price: 0.01,
formattedPrice: "$0.01",
trackId: 67890,
trackName: "Even Better App",
version: "1.2.0"
),
]
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"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/masTests/JSON/search/things-that-go-bump.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"trackName": "Things That Go Bump",
"trackId": 1472954003,
"sellerName": "Tinybop Inc.",
"price": 0.99,
"fileSizeBytes": "12345678",
"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»-(¯`·.·´¯)->",
"primaryGenreId": 6014,
"primaryGenreName": "Games",
Expand Down
Loading
Loading
0