Skip to content

Commit c4c51ab

Browse files
committed
address feedback and adopt to latest API
1 parent 4402388 commit c4c51ab

File tree

1 file changed

+31
-40
lines changed

1 file changed

+31
-40
lines changed

Sources/Commands/SwiftPackageCollectionsTool.swift

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ import TSCBasic
1616
import TSCUtility
1717

1818
private enum CollectionsError: Swift.Error {
19+
case invalidArgument(String)
1920
case invalidVersionString(String)
20-
case missingArgument(String)
2121
case noCollectionMatchingURL(String)
2222
}
2323

2424
extension CollectionsError: CustomStringConvertible {
2525
var description: String {
2626
switch self {
27+
case .invalidArgument(let argumentName):
28+
return "invalid argument '\(argumentName)'"
2729
case .invalidVersionString(let versionString):
2830
return "invalid version string '\(versionString)'"
29-
case .missingArgument(let argumentName):
30-
return "missing argument '\(argumentName)'"
3131
case .noCollectionMatchingURL(let url):
3232
return "no collection matching URL '\(url)'"
3333
}
@@ -83,7 +83,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
8383
var jsonOptions: JSONOptions
8484

8585
mutating func run() throws {
86-
let profiles: [PackageCollectionsModel.Profile] = try await { self.collections.listProfiles(callback: $0) }
86+
let profiles: [PackageCollectionsModel.Profile] = try tsc_await { self.collections.listProfiles(callback: $0) }
8787

8888
if jsonOptions.json {
8989
try JSONEncoder().print(profiles)
@@ -107,7 +107,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
107107
var profileOptions: ProfileOptions
108108

109109
mutating func run() throws {
110-
let collections = try await { self.collections.listCollections(identifiers: nil, in: profileOptions.usedProfile, callback: $0) }
110+
let collections = try tsc_await { self.collections.listCollections(identifiers: nil, in: profileOptions.usedProfile, callback: $0) }
111111

112112
if jsonOptions.json {
113113
try JSONEncoder().print(collections)
@@ -126,7 +126,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
126126
var profileOptions: ProfileOptions
127127

128128
mutating func run() throws {
129-
let collections = try await { self.collections.refreshCollections(in: profileOptions.usedProfile, callback: $0) }
129+
let collections = try tsc_await { self.collections.refreshCollections(in: profileOptions.usedProfile, callback: $0) }
130130
print("Refreshed \(collections.count) configured package collections.")
131131
}
132132
}
@@ -135,7 +135,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
135135
static let configuration = CommandConfiguration(abstract: "Add a new collection")
136136

137137
@Argument(help: "URL of the collection to add")
138-
var collectionUrl: String?
138+
var collectionUrl: String
139139

140140
@Option(name: .long, help: "Sort order for the added collection")
141141
var order: Int?
@@ -144,12 +144,12 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
144144
var profileOptions: ProfileOptions
145145

146146
mutating func run() throws {
147-
guard let collectionUrlString = collectionUrl, let collectionUrl = URL(string: collectionUrlString) else {
148-
throw CollectionsError.missingArgument("collectionUrl")
147+
guard let collectionUrl = URL(string: collectionUrl) else {
148+
throw CollectionsError.invalidArgument("collectionUrl")
149149
}
150150

151-
let source = PackageCollectionsModel.CollectionSource(url: collectionUrl)
152-
let collection = try await { self.collections.addCollection(source, order: order, to: profileOptions.usedProfile, callback: $0) }
151+
let source = PackageCollectionsModel.CollectionSource(type: .feed, url: collectionUrl)
152+
let collection = try tsc_await { self.collections.addCollection(source, order: order, to: profileOptions.usedProfile, callback: $0) }
153153

154154
print("Added \"\(collection.name)\" to your package collections.")
155155
}
@@ -162,21 +162,21 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
162162
var profileOptions: ProfileOptions
163163

164164
@Argument(help: "URL of the collection to remove")
165-
var collectionUrl: String?
165+
var collectionUrl: String
166166

167167
mutating func run() throws {
168-
guard let collectionUrlString = collectionUrl, let collectionUrl = URL(string: collectionUrlString) else {
169-
throw CollectionsError.missingArgument("collectionUrl")
168+
guard let collectionUrl = URL(string: collectionUrl) else {
169+
throw CollectionsError.invalidArgument("collectionUrl")
170170
}
171171

172-
let collections = try await { self.collections.listCollections(identifiers: nil, in: profileOptions.usedProfile, callback: $0) }
173-
let source = PackageCollectionsModel.CollectionSource(url: collectionUrl)
172+
let collections = try tsc_await { self.collections.listCollections(identifiers: nil, in: profileOptions.usedProfile, callback: $0) }
173+
let source = PackageCollectionsModel.CollectionSource(type: .feed, url: collectionUrl)
174174

175175
guard let collection = collections.first(where: { $0.source == source }) else {
176-
throw CollectionsError.noCollectionMatchingURL(collectionUrlString)
176+
throw CollectionsError.noCollectionMatchingURL(collectionUrl.absoluteString)
177177
}
178178

179-
_ = try await { self.collections.removeCollection(source, from: profileOptions.usedProfile, callback: $0) }
179+
_ = try tsc_await { self.collections.removeCollection(source, from: profileOptions.usedProfile, callback: $0) }
180180
print("Removed \"\(collection.name)\" from your package collections.")
181181
}
182182
}
@@ -185,21 +185,21 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
185185
static let configuration = CommandConfiguration(abstract: "Get metadata for a configured collection")
186186

187187
@Argument(help: "URL of the collection to describe")
188-
var collectionUrl: String?
188+
var collectionUrl: String
189189

190190
@OptionGroup
191191
var profileOptions: ProfileOptions
192192

193193
mutating func run() throws {
194-
guard let collectionUrlString = collectionUrl, let collectionUrl = URL(string: collectionUrlString) else {
195-
throw CollectionsError.missingArgument("collectionUrl")
194+
guard let collectionUrl = URL(string: collectionUrl) else {
195+
throw CollectionsError.invalidArgument("collectionUrl")
196196
}
197197

198-
let collections = try await { self.collections.listCollections(identifiers: nil, in: profileOptions.usedProfile, callback: $0) }
199-
let source = PackageCollectionsModel.CollectionSource(url: collectionUrl)
198+
let collections = try tsc_await { self.collections.listCollections(identifiers: nil, in: profileOptions.usedProfile, callback: $0) }
199+
let source = PackageCollectionsModel.CollectionSource(type: .feed, url: collectionUrl)
200200

201201
guard let collection = collections.first(where: { $0.source == source }) else {
202-
throw CollectionsError.noCollectionMatchingURL(collectionUrlString)
202+
throw CollectionsError.noCollectionMatchingURL(collectionUrl.absoluteString)
203203
}
204204

205205
let description = optionalRow("Description", collection.description)
@@ -237,23 +237,19 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
237237
var searchMethod: SearchMethod
238238

239239
@Argument(help: "Search query")
240-
var searchQuery: String?
240+
var searchQuery: String
241241

242242
mutating func run() throws {
243-
guard let searchQuery = searchQuery else {
244-
throw CollectionsError.missingArgument("searchQuery")
245-
}
246-
247243
switch searchMethod {
248244
case .keywords:
249-
let results = try await { collections.findPackages(searchQuery, collections: nil, profile: profileOptions.usedProfile, callback: $0) }
245+
let results = try tsc_await { collections.findPackages(searchQuery, collections: nil, profile: profileOptions.usedProfile, callback: $0) }
250246

251247
results.items.forEach {
252-
print("\($0.package.repository.url): \($0.package.description ?? "")")
248+
print("\($0.package.repository.url): \($0.package.summary ?? "")")
253249
}
254250

255251
case .module:
256-
let results = try await { collections.findTargets(searchQuery, searchType: .exactMatch, collections: nil, profile: profileOptions.usedProfile, callback: $0) }
252+
let results = try tsc_await { collections.findTargets(searchQuery, searchType: .exactMatch, collections: nil, profile: profileOptions.usedProfile, callback: $0) }
257253

258254
results.items.forEach {
259255
$0.packages.forEach {
@@ -276,7 +272,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
276272
var profileOptions: ProfileOptions
277273

278274
@Argument(help: "URL of the package to get information for")
279-
var packageUrl: String?
275+
var packageUrl: String
280276

281277
@Option(name: .long, help: "Version of the package to get information for")
282278
var version: String?
@@ -290,24 +286,19 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
290286
let platforms = optionalRow("Verified Platforms", version.verifiedPlatforms?.map { $0.name }.joined(separator: ", "))
291287
let swiftVersions = optionalRow("Verified Swift Versions", version.verifiedSwiftVersions?.map { $0.rawValue }.joined(separator: ", "))
292288
let license = optionalRow("License", version.license?.type.description)
293-
let cves = optionalRow("CVEs", version.cves?.map { $0.identifier }.joined(separator: ", "))
294289

295290
return """
296291
\(version.version)
297292
Package Name: \(version.packageName)
298-
Modules: \(modules)\(platforms)\(swiftVersions)\(license)\(cves)
293+
Modules: \(modules)\(platforms)\(swiftVersions)\(license)
299294
"""
300295
}
301296

302297
mutating func run() throws {
303-
guard let packageUrl = packageUrl else {
304-
throw CollectionsError.missingArgument("packageUrl")
305-
}
306-
307298
let identity = PackageReference.computeIdentity(packageURL: packageUrl)
308299
let reference = PackageReference(identity: identity, path: packageUrl)
309300

310-
let result = try await { self.collections.getPackageMetadata(reference, profile: profileOptions.usedProfile, callback: $0) }
301+
let result = try tsc_await { self.collections.getPackageMetadata(reference, profile: profileOptions.usedProfile, callback: $0) }
311302

312303
if let versionString = version {
313304
guard let version = TSCUtility.Version(string: versionString), let result = result.package.versions.first(where: { $0.version == version }), let printedResult = printVersion(result) else {

0 commit comments

Comments
 (0)