@@ -38,7 +38,7 @@ struct JSONOptions: ParsableArguments {
38
38
39
39
public struct SwiftPackageCollectionsTool : ParsableCommand {
40
40
public static var configuration = CommandConfiguration (
41
- commandName: " package-collections " ,
41
+ commandName: " package-collection " ,
42
42
_superCommandName: " swift " ,
43
43
abstract: " Interact with package collections " ,
44
44
discussion: " SEE ALSO: swift build, swift package, swift run, swift test " ,
@@ -202,7 +202,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
202
202
let license = optionalRow ( " License " , version. license? . type. description)
203
203
204
204
return """
205
- \( version. version)
205
+ \( version. version)
206
206
Package Name: \( version. packageName)
207
207
Modules: \( modules) \( platforms) \( swiftVersions) \( license)
208
208
"""
@@ -222,17 +222,18 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
222
222
throw CollectionsError . invalidVersionString ( versionString)
223
223
}
224
224
225
- print ( " Version: \( printedResult) " )
225
+ print ( " \( indent ( ) ) Version: \( printedResult) " )
226
226
} else {
227
227
let description = optionalRow ( " Description " , result. package . summary)
228
228
let versions = result. package . versions. map { " \( $0. version) " } . joined ( separator: " , " )
229
229
let watchers = optionalRow ( " Watchers " , result. package . watchersCount? . description)
230
230
let readme = optionalRow ( " Readme " , result. package . readmeURL? . absoluteString)
231
231
let authors = optionalRow ( " Authors " , result. package . authors? . map { $0. username } . joined ( separator: " , " ) )
232
- let latestVersion = optionalRow ( " -------------------------------------------------------------- \n Latest Version" , printVersion ( result. package . latestVersion) )
232
+ let latestVersion = optionalRow ( " \( String ( repeating : " - " , count : 60 ) ) \n \( indent ( ) ) Latest Version" , printVersion ( result. package . latestVersion) )
233
233
234
234
print ( """
235
- \( description) Available Versions: \( versions) \( watchers) \( readme) \( authors) \( latestVersion)
235
+ \( description)
236
+ Available Versions: \( versions) \( watchers) \( readme) \( authors) \( latestVersion)
236
237
""" )
237
238
}
238
239
} catch { // assume URL is for a collection
@@ -252,24 +253,27 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
252
253
253
254
let description = optionalRow ( " Description " , collection. overview)
254
255
let keywords = optionalRow ( " Keywords " , collection. keywords? . joined ( separator: " , " ) )
255
- let createdAt = DateFormatter ( ) . string ( from: collection. createdAt)
256
- let packages = collection. packages. map { " \( $0. repository. url) " } . joined ( separator: " \n " )
256
+ let createdAt = optionalRow ( " Created At " , DateFormatter ( ) . string ( from: collection. createdAt) )
257
+ let packages = collection. packages. map { " \( $0. repository. url) " } . joined ( separator: " \n \( indent ( levels : 2 ) ) " )
257
258
258
259
print ( """
259
260
Name: \( collection. name)
260
- Source: \( collection. source. url) \( description) \( keywords)
261
- Created At: \( createdAt)
261
+ Source: \( collection. source. url) \( description) \( keywords) \( createdAt)
262
262
Packages:
263
- \( packages)
263
+ \( packages)
264
264
""" )
265
265
}
266
266
}
267
267
}
268
268
}
269
269
270
- private func optionalRow( _ title: String , _ contents: String ? ) -> String {
271
- if let contents = contents {
272
- return " \n \( title) : \( contents) \n "
270
+ private func indent( levels: Int = 1 ) -> String {
271
+ return String ( repeating: " " , count: levels)
272
+ }
273
+
274
+ private func optionalRow( _ title: String , _ contents: String ? , indentationLevel: Int = 1 ) -> String {
275
+ if let contents = contents, !contents. isEmpty {
276
+ return " \n \( indent ( levels: indentationLevel) ) \( title) : \( contents) "
273
277
} else {
274
278
return " "
275
279
}
0 commit comments