mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Swiftformat on githooks + New swift run tools setup command (#563)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
enum Utilities {
|
||||
enum Error: LocalizedError {
|
||||
case scriptFailed(command: String, path: String)
|
||||
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case let .scriptFailed(command, path):
|
||||
return "command \(command) failed in path: \(path)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static var projectDirectoryURL: URL { URL(filePath: FileManager.default.currentDirectoryPath) }
|
||||
|
||||
/// Runs a command in zsh.
|
||||
@discardableResult
|
||||
static func zsh(_ command: String, workingDirectoryURL: URL = projectDirectoryURL) throws -> String? {
|
||||
let process = Process()
|
||||
process.executableURL = URL(filePath: "/bin/zsh")
|
||||
process.arguments = ["-c", command]
|
||||
process.currentDirectoryURL = workingDirectoryURL
|
||||
|
||||
let outputPipe = Pipe()
|
||||
process.standardOutput = outputPipe
|
||||
|
||||
try process.run()
|
||||
process.waitUntilExit()
|
||||
|
||||
guard process.terminationReason == .exit, process.terminationStatus == 0 else { throw Error.scriptFailed(command: command, path: workingDirectoryURL.absoluteString) }
|
||||
|
||||
guard let outputData = try outputPipe.fileHandleForReading.readToEnd() else { return nil }
|
||||
return String(data: outputData, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user