Files
letro-ios/Tools/Sources/Utilities.swift
Mauro b03bc997fc Translations workflow and tools (#768)
* Translations workflow and tools

* improved the name of the workflow

* need this commit to trigger the workflow for the first time

* swift tools can now run on CI

* only strings and stringsdict will be committed

* fixed a workflow issue

* starting the workflow to save it

* fixing downgrade issues

* fixing URL usage

* install localazy

* fixing add-paths typo

* downloaded strings

* removing on push trigger

* Update Tools/Sources/DownloadTranslations.swift

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* Added locheck for string verification

* code formatting improvement

* Update Tools/Sources/Locheck.swift

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* pr suggestion

---------

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
2023-04-05 19:36:51 +02:00

38 lines
1.3 KiB
Swift

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(fileURLWithPath: 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(fileURLWithPath: "/bin/zsh")
process.arguments = ["-cu", 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)
}
}