                 Self.exit(withError: error)
             }
         }
-        
+
         return try handler(collections)
     }
 }


        mutating func run() throws {
            let collections = try with { collections in
                return try tsc_await { collections.listCollections(identifiers: nil, callback: $0) }
            }

            if jsonOptions.json {
                try JSONEncoder.makeWithDefaults().print(collections)
            } else {
                collections.forEach {

                    if version != nil {
                        throw error
                    }

                    guard let collectionUrl = URL(string: packageUrl) else {
                        throw CollectionsError.invalidArgument("collectionUrl")
                    }

                    do {
                        let source = PackageCollectionsModel.CollectionSource(type: .json, url: collectionUrl)
                        let collection = try tsc_await { collections.getCollection(source, callback: $0) }

                        let description = optionalRow("Description", collection.overview)
                        let keywords = optionalRow("Keywords", collection.keywords?.joined(separator: ", "))
                        let createdAt = optionalRow("Created At", DateFormatter().string(from: collection.createdAt))
                        let packages = collection.packages.map { "\($0.repository.url)" }.joined(separator: "\n\(indent(levels: 2))")

                        if jsonOptions.json {
                            try JSONEncoder.makeWithDefaults().print(collection)
                        } else {
                            print("""
                                Name: \(collection.name)
                                Source: \(collection.source.url)\(description)\(keywords)\(createdAt)
                                Packages:
                                    \(packages)
                            """)
                        }
                    } catch {
                        print("Failed to get metadata. The given URL neither belongs to a valid collection nor a package in an imported collection.")
                    }
                }
            }
