@@ -108,7 +108,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
108
108
static let configuration = CommandConfiguration ( abstract: " Add a new collection " )
109
109
110
110
@Argument ( help: " URL of the collection to add " )
111
- var collectionUrl : String
111
+ var collectionURL : String
112
112
113
113
@Option ( name: . long, help: " Sort order for the added collection " )
114
114
var order : Int ?
@@ -120,11 +120,9 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
120
120
var skipSignatureCheck : Bool = false
121
121
122
122
mutating func run( ) throws {
123
- guard let collectionUrl = URL ( string: collectionUrl) else {
124
- throw CollectionsError . invalidArgument ( " collectionUrl " )
125
- }
123
+ let collectionURL = try url ( self . collectionURL)
126
124
127
- let source = PackageCollectionsModel . CollectionSource ( type: . json, url: collectionUrl , skipSignatureCheck: self . skipSignatureCheck)
125
+ let source = PackageCollectionsModel . CollectionSource ( type: . json, url: collectionURL , skipSignatureCheck: self . skipSignatureCheck)
128
126
let collection : PackageCollectionsModel . Collection = try with { collections in
129
127
do {
130
128
let userTrusted = self . trustUnsigned
@@ -155,14 +153,12 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
155
153
static let configuration = CommandConfiguration ( abstract: " Remove a configured collection " )
156
154
157
155
@Argument ( help: " URL of the collection to remove " )
158
- var collectionUrl : String
156
+ var collectionURL : String
159
157
160
158
mutating func run( ) throws {
161
- guard let collectionUrl = URL ( string: collectionUrl) else {
162
- throw CollectionsError . invalidArgument ( " collectionUrl " )
163
- }
159
+ let collectionURL = try url ( self . collectionURL)
164
160
165
- let source = PackageCollectionsModel . CollectionSource ( type: . json, url: collectionUrl )
161
+ let source = PackageCollectionsModel . CollectionSource ( type: . json, url: collectionURL )
166
162
try with { collections in
167
163
let collection = try tsc_await { collections. getCollection ( source, callback: $0) }
168
164
_ = try tsc_await { collections. removeCollection ( source, callback: $0) }
@@ -229,7 +225,7 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
229
225
var jsonOptions : JSONOptions
230
226
231
227
@Argument ( help: " URL of the package or collection to get information for " )
232
- var packageUrl : String
228
+ var packageURL : String
233
229
234
230
@Option ( name: . long, help: " Version of the package to get information for " )
235
231
var version : String ?
@@ -268,8 +264,8 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
268
264
269
265
mutating func run( ) throws {
270
266
try with { collections in
271
- let identity = PackageIdentity ( url: packageUrl )
272
- let reference = PackageReference . remote ( identity: identity, location: packageUrl )
267
+ let identity = PackageIdentity ( url: packageURL )
268
+ let reference = PackageReference . remote ( identity: identity, location: packageURL )
273
269
274
270
do { // assume URL is for a package in an imported collection
275
271
let result = try tsc_await { collections. getPackageMetadata ( reference, callback: $0) }
@@ -307,12 +303,10 @@ public struct SwiftPackageCollectionsTool: ParsableCommand {
307
303
throw error
308
304
}
309
305
310
- guard let collectionUrl = URL ( string: packageUrl) else {
311
- throw CollectionsError . invalidArgument ( " collectionUrl " )
312
- }
306
+ let collectionURL = try url ( self . packageURL)
313
307
314
308
do {
315
- let source = PackageCollectionsModel . CollectionSource ( type: . json, url: collectionUrl )
309
+ let source = PackageCollectionsModel . CollectionSource ( type: . json, url: collectionURL )
316
310
let collection = try tsc_await { collections. getCollection ( source, callback: $0) }
317
311
318
312
let description = optionalRow ( " Description " , collection. overview)
@@ -374,4 +368,16 @@ private extension ParsableCommand {
374
368
375
369
return try handler ( collections)
376
370
}
371
+
372
+ func url( _ urlString: String ) throws -> Foundation . URL {
373
+ guard let url = URL ( string: urlString) else {
374
+ let filePrefix = " file:// "
375
+ guard urlString. hasPrefix ( filePrefix) else {
376
+ throw CollectionsError . invalidArgument ( " collectionURL " )
377
+ }
378
+ // URL(fileURLWithPath:) can handle whitespaces in path
379
+ return URL ( fileURLWithPath: String ( urlString. dropFirst ( filePrefix. count) ) )
380
+ }
381
+ return url
382
+ }
377
383
}
0 commit comments