From 5c2c54fa9f5e3738a8a4330dfafee41a0b2a9ac4 Mon Sep 17 00:00:00 2001 From: Tom Lokhorst Date: Thu, 13 Dec 2018 17:09:32 +0100 Subject: [PATCH] Improved errors (#470) * Collect all commandline argument errors, and show them at once * Only touch file when running generate command. To prevent warnings when using --help or --version * Move Rswift environment validation to separate file * Cleanup --- Sources/RswiftCore/EnvironmentValidation.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sources/RswiftCore/EnvironmentValidation.swift b/Sources/RswiftCore/EnvironmentValidation.swift index 1a68a60b..4c37cdcb 100644 --- a/Sources/RswiftCore/EnvironmentValidation.swift +++ b/Sources/RswiftCore/EnvironmentValidation.swift @@ -17,10 +17,9 @@ public func validateRswiftEnvironment( commandLineArguments: [String]) -> [String] { var errors: [String] = [] - var outputIsDirectory = false + var outputFileForError = outputURL.path if outputURL.pathExtension != "swift" { - outputIsDirectory = true var error = "Output path must specify a file, it should not be a directory." if FileManager.default.directoryExists(atPath: outputURL.path) { @@ -30,7 +29,10 @@ public func validateRswiftEnvironment( .map { $0.replacingOccurrences(of: outputURL.path, with: rswiftGeneratedFile) } .map { $0.replacingOccurrences(of: sourceRootPath, with: "$SRCROOT") } .map { $0.contains(" ") ? "\"\($0)\"" : $0 } + error += "\nExample: " + commandParts.joined(separator: " ") + + outputFileForError = rswiftGeneratedFile } errors.append(error) @@ -41,11 +43,8 @@ public func validateRswiftEnvironment( } if !scriptOutputFiles.contains(outputURL.path) { - var prettyPath = outputURL.path.replacingOccurrences(of: sourceRootPath, with: "$SRCROOT") - if outputIsDirectory { - prettyPath += "/R.generated.swift" - } - errors.append("Build phase Output Files do not contain '\(prettyPath)'.") + let path = outputFileForError.replacingOccurrences(of: sourceRootPath, with: "$SRCROOT") + errors.append("Build phase Output Files do not contain '\(path)'.") } return errors