@@ -16,18 +16,18 @@ import TSCBasic
16
16
import TSCUtility
17
17
18
18
private enum CollectionsError : Swift . Error {
19
+ case invalidArgument( String )
19
20
case invalidVersionString( String )
20
- case missingArgument( String )
21
21
case noCollectionMatchingURL( String )
22
22
}
23
23
24
24
extension CollectionsError : CustomStringConvertible {
25
25
var description : String {
26
26
switch self {
27
+ case . invalidArgument( let argumentName) :
28
+ return " invalid argument ' \( argumentName) ' "
27
29
case . invalidVersionString( let versionString) :
28
30
return " invalid version string ' \( versionString) ' "
29
- case . missingArgument( let argumentName) :
30
- return " missing argument ' \( argumentName) ' "
31
31
case . noCollectionMatchingURL( let url) :
32
32
return " no collection matching URL ' \( url) ' "
33
33
}
@@ -83,7 +83,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
83
83
var jsonOptions : JSONOptions
84
84
85
85
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) }
87
87
88
88
if jsonOptions. json {
89
89
try JSONEncoder ( ) . print ( profiles)
@@ -107,7 +107,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
107
107
var profileOptions : ProfileOptions
108
108
109
109
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) }
111
111
112
112
if jsonOptions. json {
113
113
try JSONEncoder ( ) . print ( collections)
@@ -126,7 +126,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
126
126
var profileOptions : ProfileOptions
127
127
128
128
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) }
130
130
print ( " Refreshed \( collections. count) configured package collections. " )
131
131
}
132
132
}
@@ -135,7 +135,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
135
135
static let configuration = CommandConfiguration ( abstract: " Add a new collection " )
136
136
137
137
@Argument ( help: " URL of the collection to add " )
138
- var collectionUrl : String ?
138
+ var collectionUrl : String
139
139
140
140
@Option ( name: . long, help: " Sort order for the added collection " )
141
141
var order : Int ?
@@ -144,12 +144,12 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
144
144
var profileOptions : ProfileOptions
145
145
146
146
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 " )
149
149
}
150
150
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) }
153
153
154
154
print ( " Added \" \( collection. name) \" to your package collections. " )
155
155
}
@@ -162,21 +162,21 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
162
162
var profileOptions : ProfileOptions
163
163
164
164
@Argument ( help: " URL of the collection to remove " )
165
- var collectionUrl : String ?
165
+ var collectionUrl : String
166
166
167
167
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 " )
170
170
}
171
171
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)
174
174
175
175
guard let collection = collections. first ( where: { $0. source == source } ) else {
176
- throw CollectionsError . noCollectionMatchingURL ( collectionUrlString )
176
+ throw CollectionsError . noCollectionMatchingURL ( collectionUrl . absoluteString )
177
177
}
178
178
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) }
180
180
print ( " Removed \" \( collection. name) \" from your package collections. " )
181
181
}
182
182
}
@@ -185,21 +185,21 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
185
185
static let configuration = CommandConfiguration ( abstract: " Get metadata for a configured collection " )
186
186
187
187
@Argument ( help: " URL of the collection to describe " )
188
- var collectionUrl : String ?
188
+ var collectionUrl : String
189
189
190
190
@OptionGroup
191
191
var profileOptions : ProfileOptions
192
192
193
193
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 " )
196
196
}
197
197
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)
200
200
201
201
guard let collection = collections. first ( where: { $0. source == source } ) else {
202
- throw CollectionsError . noCollectionMatchingURL ( collectionUrlString )
202
+ throw CollectionsError . noCollectionMatchingURL ( collectionUrl . absoluteString )
203
203
}
204
204
205
205
let description = optionalRow ( " Description " , collection. description)
@@ -237,23 +237,19 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
237
237
var searchMethod : SearchMethod
238
238
239
239
@Argument ( help: " Search query " )
240
- var searchQuery : String ?
240
+ var searchQuery : String
241
241
242
242
mutating func run( ) throws {
243
- guard let searchQuery = searchQuery else {
244
- throw CollectionsError . missingArgument ( " searchQuery " )
245
- }
246
-
247
243
switch searchMethod {
248
244
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) }
250
246
251
247
results. items. forEach {
252
- print ( " \( $0. package . repository. url) : \( $0. package . description ?? " " ) " )
248
+ print ( " \( $0. package . repository. url) : \( $0. package . summary ?? " " ) " )
253
249
}
254
250
255
251
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) }
257
253
258
254
results. items. forEach {
259
255
$0. packages. forEach {
@@ -276,7 +272,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
276
272
var profileOptions : ProfileOptions
277
273
278
274
@Argument ( help: " URL of the package to get information for " )
279
- var packageUrl : String ?
275
+ var packageUrl : String
280
276
281
277
@Option ( name: . long, help: " Version of the package to get information for " )
282
278
var version : String ?
@@ -290,24 +286,19 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
290
286
let platforms = optionalRow ( " Verified Platforms " , version. verifiedPlatforms? . map { $0. name } . joined ( separator: " , " ) )
291
287
let swiftVersions = optionalRow ( " Verified Swift Versions " , version. verifiedSwiftVersions? . map { $0. rawValue } . joined ( separator: " , " ) )
292
288
let license = optionalRow ( " License " , version. license? . type. description)
293
- let cves = optionalRow ( " CVEs " , version. cves? . map { $0. identifier } . joined ( separator: " , " ) )
294
289
295
290
return """
296
291
\( version. version)
297
292
Package Name: \( version. packageName)
298
- Modules: \( modules) \( platforms) \( swiftVersions) \( license) \( cves )
293
+ Modules: \( modules) \( platforms) \( swiftVersions) \( license)
299
294
"""
300
295
}
301
296
302
297
mutating func run( ) throws {
303
- guard let packageUrl = packageUrl else {
304
- throw CollectionsError . missingArgument ( " packageUrl " )
305
- }
306
-
307
298
let identity = PackageReference . computeIdentity ( packageURL: packageUrl)
308
299
let reference = PackageReference ( identity: identity, path: packageUrl)
309
300
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) }
311
302
312
303
if let versionString = version {
313
304
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