mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
72 lines
2.0 KiB
Swift
72 lines
2.0 KiB
Swift
//
|
|
// main.swift
|
|
// SwiftFormat
|
|
//
|
|
// Created by Nick Lockwood on 12/08/2016.
|
|
// Copyright 2016 Nick Lockwood
|
|
//
|
|
// Distributed under the permissive zlib license
|
|
// Get the latest version from here:
|
|
//
|
|
// https://github.com/nicklockwood/SwiftFormat
|
|
//
|
|
// This software is provided 'as-is', without any express or implied
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
// arising from the use of this software.
|
|
//
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
// including commercial applications, and to alter it and redistribute it
|
|
// freely, subject to the following restrictions:
|
|
//
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
// claim that you wrote the original software. If you use this software
|
|
// in a product, an acknowledgment in the product documentation would be
|
|
// appreciated but is not required.
|
|
//
|
|
// 2. Altered source versions must be plainly marked as such, and must not be
|
|
// misrepresented as being the original software.
|
|
//
|
|
// 3. This notice may not be removed or altered from any source distribution.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension String {
|
|
var inDefault: String { return "\u{001B}[39m\(self)" }
|
|
var inRed: String { return "\u{001B}[31m\(self)\u{001B}[0m" }
|
|
var inGreen: String { return "\u{001B}[32m\(self)\u{001B}[0m" }
|
|
var inYellow: String { return "\u{001B}[33m\(self)\u{001B}[0m" }
|
|
}
|
|
|
|
extension FileHandle: TextOutputStream {
|
|
public func write(_ string: String) {
|
|
if let data = string.data(using: .utf8) {
|
|
write(data)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var stderr = FileHandle.standardError
|
|
|
|
CLI.print = { message, type in
|
|
switch type {
|
|
case .info:
|
|
print(message.inDefault)
|
|
case .success:
|
|
print(message.inGreen)
|
|
case .error:
|
|
print(message.inRed, to: &stderr)
|
|
case .warning:
|
|
print(message.inYellow, to: &stderr)
|
|
case .output:
|
|
print(message)
|
|
}
|
|
}
|
|
|
|
CLI.readLine = {
|
|
readLine(strippingNewline: false)
|
|
}
|
|
|
|
// Pass in arguments
|
|
processArguments(CommandLine.arguments)
|