Files
swift-nio-imap/Sources/NIOIMAPFormatter/main.swift
T
David Evans fd3e16ad49 Implement RFC 6154 SPECIAL-USE (#303)
* Implement

* Tests for new types

* Tests

* Fix

* Fix tests

* Fix sanity

* Fix warnings

* Silence warnings
2020-09-08 11:25:48 +01:00

60 lines
1.6 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2020 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Foundation
#if canImport(Darwin)
import Darwin
#else
import Glibc
#endif
#if os(Linux) || os(macOS)
let filePath: String
#if compiler(>=5.3)
filePath = (#file)
#else
filePath = (#file)
#endif
let swiftFormat = URL(fileURLWithPath: CommandLine.arguments.first!)
.deletingLastPathComponent()
.appendingPathComponent("swiftformat")
let sourceCode = URL(fileURLWithPath: filePath)
.deletingLastPathComponent()
.deletingLastPathComponent()
.deletingLastPathComponent()
if #available(macOS 10.13, /* Linux */ *) {
print("Alright, let's format the source code in \(sourceCode) using \(swiftFormat).")
let process = Process()
process.executableURL = swiftFormat
process.arguments = [sourceCode.path]
try process.run()
process.waitUntilExit()
switch process.terminationReason {
case .exit:
exit(process.terminationStatus)
case .uncaughtSignal:
kill(getpid(), process.terminationStatus)
#if canImport(Darwin)
@unknown default:
exit(process.terminationStatus)
#endif
}
}
#endif
// Fallthrough, something wasn't right
print("ERROR: Unsupported OS\n")
exit(EXIT_FAILURE)