From d7d3d74b5364acff9dcd2b4e20fef7394e5e359e Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Wed, 27 May 2020 23:46:59 +0100 Subject: [PATCH] Added logging of config file location --- Sources/CommandLine.swift | 20 +++++++++++++------- Sources/SwiftFormat.swift | 5 +++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Sources/CommandLine.swift b/Sources/CommandLine.swift index 5bb3000c..0709f26e 100644 --- a/Sources/CommandLine.swift +++ b/Sources/CommandLine.swift @@ -675,7 +675,11 @@ func inferOptions(from inputURLs: [URL], options: FileOptions) -> (Int, FormatOp var filesParsed = 0 let baseOptions = Options(fileOptions: options) for inputURL in inputURLs { - errors += enumerateFiles(withInputURL: inputURL, options: baseOptions) { inputURL, _, _ in + errors += enumerateFiles( + withInputURL: inputURL, + options: baseOptions, + logger: { print($0, as: .info) } + ) { inputURL, _, _ in guard let input = try? String(contentsOf: inputURL) else { throw FormatError.reading("Failed to read file \(inputURL.path)") } @@ -784,12 +788,14 @@ func processInput(_ inputURLs: [URL], // Format files var errors = [Error]() for inputURL in inputURLs { - errors += enumerateFiles(withInputURL: inputURL, - outputURL: outputURL, - options: options, - concurrent: !verbose, - skipped: skippedHandler) { inputURL, outputURL, options in - + errors += enumerateFiles( + withInputURL: inputURL, + outputURL: outputURL, + options: options, + concurrent: !verbose, + logger: { print($0, as: .info) }, + skipped: skippedHandler + ) { inputURL, outputURL, options in guard let input = try? String(contentsOf: inputURL) else { throw FormatError.reading("Failed to read file \(inputURL.path)") } diff --git a/Sources/SwiftFormat.swift b/Sources/SwiftFormat.swift index f15d6961..636e51ca 100644 --- a/Sources/SwiftFormat.swift +++ b/Sources/SwiftFormat.swift @@ -73,6 +73,9 @@ public typealias FileEnumerationHandler = ( _ options: Options ) throws -> () throws -> Void +/// Callback for info-level logging +public typealias Logger = (String) -> Void + /// Enumerate all swift files at the specified location and (optionally) calculate an output file URL for each. /// Ignores the file if any of the excluded file URLs is a prefix of the input file URL. /// @@ -86,6 +89,7 @@ public func enumerateFiles(withInputURL inputURL: URL, outputURL: URL? = nil, options baseOptions: Options = .default, concurrent: Bool = true, + logger print: Logger? = nil, skipped: FileEnumerationHandler? = nil, handler: @escaping FileEnumerationHandler) -> [Error] { let manager = FileManager.default @@ -234,6 +238,7 @@ public func enumerateFiles(withInputURL inputURL: URL, let data = try Data(contentsOf: configFile) let args = try parseConfigFile(data) try options.addArguments(args, in: inputURL.path) + print?("Reading config file at \(configFile.path)") } let versionFile = inputURL.appendingPathComponent(swiftVersionFile) if manager.fileExists(atPath: versionFile.path) {