Skip to content

Commit 8eaf620

Browse files
Command plugin should log output to stderr, not stdout
1 parent 1c45d06 commit 8eaf620

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Plugins/OpenAPIGeneratorCommand/plugin.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,27 @@ extension SwiftOpenAPIGeneratorPlugin: CommandPlugin {
6565
var hadASuccessfulRun = false
6666

6767
for target in targets {
68-
print("Considering target '\(target.name)':")
68+
log("Considering target '\(target.name)':")
6969
guard let swiftTarget = target as? SwiftSourceModuleTarget else {
70-
print("- Not a swift source module. Can't generate OpenAPI code.")
70+
log("- Not a swift source module. Can't generate OpenAPI code.")
7171
continue
7272
}
7373
do {
74-
print("- Trying OpenAPI code generation.")
74+
log("- Trying OpenAPI code generation.")
7575
try runCommand(
7676
targetWorkingDirectory: target.directory,
7777
tool: context.tool,
7878
sourceFiles: swiftTarget.sourceFiles,
7979
targetName: target.name
8080
)
81-
print("- ✅ OpenAPI code generation for target '\(target.name)' successfully completed.")
81+
log("- ✅ OpenAPI code generation for target '\(target.name)' successfully completed.")
8282
hadASuccessfulRun = true
8383
} catch let error as PluginError {
8484
if error.isMisconfigurationError {
85-
print("- Stopping because target isn't configured for OpenAPI code generation.")
85+
log("- Stopping because target is misconfigured for OpenAPI code generation.")
8686
throw error
8787
} else {
88-
print("- OpenAPI code generation failed with error.")
88+
log("- OpenAPI code generation failed with error.")
8989
throw error
9090
}
9191
}
@@ -94,3 +94,7 @@ extension SwiftOpenAPIGeneratorPlugin: CommandPlugin {
9494
guard hadASuccessfulRun else { throw PluginError.noTargetsWithExpectedFiles(targetNames: targets.map(\.name)) }
9595
}
9696
}
97+
98+
private func log(_ message: @autoclosure () -> String) {
99+
FileHandle.standardError.write(Data(message().appending("\n").utf8))
100+
}

0 commit comments

Comments
 (0)