@@ -53,12 +53,12 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
53
53
List . self,
54
54
Refresh . self,
55
55
Remove . self,
56
- Search . self
56
+ Search . self,
57
57
] ,
58
- helpNames: [ . short, . long, . customLong( " help " , withSingleDash: true ) ] )
58
+ helpNames: [ . short, . long, . customLong( " help " , withSingleDash: true ) ]
59
+ )
59
60
60
- public init ( ) {
61
- }
61
+ public init ( ) { }
62
62
63
63
// MARK: Collections
64
64
@@ -70,10 +70,10 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
70
70
71
71
mutating func run( ) throws {
72
72
let collections = try with { collections in
73
- return try tsc_await { collections. listCollections ( identifiers: nil , callback: $0) }
73
+ try tsc_await { collections. listCollections ( identifiers: nil , callback: $0) }
74
74
}
75
75
76
- if jsonOptions. json {
76
+ if self . jsonOptions. json {
77
77
try JSONEncoder . makeWithDefaults ( ) . print ( collections)
78
78
} else {
79
79
collections. forEach {
@@ -88,7 +88,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
88
88
89
89
mutating func run( ) throws {
90
90
let collections = try with { collections in
91
- return try tsc_await { collections. refreshCollections ( callback: $0) }
91
+ try tsc_await { collections. refreshCollections ( callback: $0) }
92
92
}
93
93
print ( " Refreshed \( collections. count) configured package collections. " )
94
94
}
@@ -102,7 +102,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
102
102
103
103
@Option ( name: . long, help: " Sort order for the added collection " )
104
104
var order : Int ?
105
-
105
+
106
106
@Flag ( name: . long, help: " Trust the collection even if it is unsigned " )
107
107
var trustUnsigned : Bool = false
108
108
@@ -121,7 +121,8 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
121
121
order: order,
122
122
trustConfirmationProvider: { _, callback in callback ( userTrusted) } ,
123
123
callback: $0
124
- ) }
124
+ )
125
+ }
125
126
} catch PackageCollectionError . trustConfirmationRequired , PackageCollectionError. untrusted {
126
127
throw CollectionsError . unsigned
127
128
}
@@ -175,7 +176,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
175
176
switch searchMethod {
176
177
case . keywords:
177
178
let results = try tsc_await { collections. findPackages ( searchQuery, collections: nil , callback: $0) }
178
-
179
+
179
180
if jsonOptions. json {
180
181
try JSONEncoder . makeWithDefaults ( ) . print ( results. items)
181
182
} else {
@@ -203,7 +204,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
203
204
// MARK: Packages
204
205
205
206
struct Describe : ParsableCommand {
206
- static var configuration = CommandConfiguration ( abstract: " Get metadata for a single package or collection " )
207
+ static var configuration = CommandConfiguration ( abstract: " Get metadata for a collection or a package included in an imported collection " )
207
208
208
209
@OptionGroup
209
210
var jsonOptions : JSONOptions
@@ -228,13 +229,13 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
228
229
version. verifiedCompatibility? . map { " ( \( $0. platform. name) , \( $0. swiftVersion. rawValue) ) " } . joined ( separator: " , " )
229
230
)
230
231
let license = optionalRow ( " License " , version. license? . type. description)
231
-
232
+
232
233
return """
233
234
\( version. version)
234
- \( printManifest ( defaultManifest) ) \( manifests) \( compatibility) \( license)
235
+ \( self . printManifest ( defaultManifest) ) \( manifests) \( compatibility) \( license)
235
236
"""
236
237
}
237
-
238
+
238
239
private func printManifest( _ manifest: PackageCollectionsModel . Package . Version . Manifest ) -> String {
239
240
let modules = manifest. targets. compactMap { $0. moduleName } . joined ( separator: " , " )
240
241
let products = optionalRow ( " Products " , manifest. products. isEmpty ? nil : manifest. products. compactMap { $0. name } . joined ( separator: " , " ) , indentationLevel: 3 )
@@ -250,15 +251,15 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
250
251
try with { collections in
251
252
let identity = PackageIdentity ( url: packageUrl)
252
253
let reference = PackageReference . remote ( identity: identity, location: packageUrl)
253
-
254
- do { // assume URL is for a package
254
+
255
+ do { // assume URL is for a package in an imported collection
255
256
let result = try tsc_await { collections. getPackageMetadata ( reference, callback: $0) }
256
-
257
+
257
258
if let versionString = version {
258
259
guard let version = TSCUtility . Version ( string: versionString) , let result = result. package . versions. first ( where: { $0. version == version } ) , let printedResult = printVersion ( result) else {
259
260
throw CollectionsError . invalidVersionString ( versionString)
260
261
}
261
-
262
+
262
263
if jsonOptions. json {
263
264
try JSONEncoder . makeWithDefaults ( ) . print ( result)
264
265
} else {
@@ -286,28 +287,32 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
286
287
if version != nil {
287
288
throw error
288
289
}
289
-
290
+
290
291
guard let collectionUrl = URL ( string: packageUrl) else {
291
292
throw CollectionsError . invalidArgument ( " collectionUrl " )
292
293
}
293
-
294
- let source = PackageCollectionsModel . CollectionSource ( type: . json, url: collectionUrl)
295
- let collection = try tsc_await { collections. getCollection ( source, callback: $0) }
296
-
297
- let description = optionalRow ( " Description " , collection. overview)
298
- let keywords = optionalRow ( " Keywords " , collection. keywords? . joined ( separator: " , " ) )
299
- let createdAt = optionalRow ( " Created At " , DateFormatter ( ) . string ( from: collection. createdAt) )
300
- let packages = collection. packages. map { " \( $0. repository. url) " } . joined ( separator: " \n \( indent ( levels: 2 ) ) " )
301
-
302
- if jsonOptions. json {
303
- try JSONEncoder . makeWithDefaults ( ) . print ( collection)
304
- } else {
305
- print ( """
306
- Name: \( collection. name)
307
- Source: \( collection. source. url) \( description) \( keywords) \( createdAt)
308
- Packages:
309
- \( packages)
310
- """ )
294
+
295
+ do {
296
+ let source = PackageCollectionsModel . CollectionSource ( type: . json, url: collectionUrl)
297
+ let collection = try tsc_await { collections. getCollection ( source, callback: $0) }
298
+
299
+ let description = optionalRow ( " Description " , collection. overview)
300
+ let keywords = optionalRow ( " Keywords " , collection. keywords? . joined ( separator: " , " ) )
301
+ let createdAt = optionalRow ( " Created At " , DateFormatter ( ) . string ( from: collection. createdAt) )
302
+ let packages = collection. packages. map { " \( $0. repository. url) " } . joined ( separator: " \n \( indent ( levels: 2 ) ) " )
303
+
304
+ if jsonOptions. json {
305
+ try JSONEncoder . makeWithDefaults ( ) . print ( collection)
306
+ } else {
307
+ print ( """
308
+ Name: \( collection. name)
309
+ Source: \( collection. source. url) \( description) \( keywords) \( createdAt)
310
+ Packages:
311
+ \( packages)
312
+ """ )
313
+ }
314
+ } catch {
315
+ print ( " Failed to get metadata. The given URL neither belongs to a valid collection nor a package in an imported collection. " )
311
316
}
312
317
}
313
318
}
@@ -328,7 +333,7 @@ private func optionalRow(_ title: String, _ contents: String?, indentationLevel:
328
333
}
329
334
330
335
private extension JSONEncoder {
331
- func print< T> ( _ value: T ) throws where T : Encodable {
336
+ func print< T> ( _ value: T ) throws where T: Encodable {
332
337
let jsonData = try self . encode ( value)
333
338
let jsonString = String ( data: jsonData, encoding: . utf8) !
334
339
Swift . print ( jsonString)
@@ -345,7 +350,7 @@ private extension ParsableCommand {
345
350
Self . exit ( withError: error)
346
351
}
347
352
}
348
-
353
+
349
354
return try handler ( collections)
350
355
}
351
356
}
0 commit comments