Upgrade to Swift 5!

This commit is contained in:
Jacob Williams
2019-03-26 08:34:06 -06:00
parent c173a81f61
commit 3cf7a9407c
3 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -1 +1 @@
4.2
5.0
+2 -2
View File
@@ -67,10 +67,10 @@ extension CommandRunning {
let process = Process()
process.arguments = args
process.launchPath = path(for: executable)
process.executableURL = URL(fileURLWithPath: path(for: executable))
process.environment = context.env
process.currentDirectoryPath = context.currentdirectory
process.currentDirectoryURL = URL(fileURLWithPath: context.currentdirectory, isDirectory: true)
process.standardInput = context.stdin.filehandle
process.standardOutput = context.stdout.filehandle
+6 -5
View File
@@ -15,11 +15,12 @@ extension Process {
/// Launches process.
///
/// - throws: CommandError.inAccessibleExecutable if command could not be executed.
@available(swift, deprecated: 5.0)
public func launchThrowably() throws {
guard Files.isExecutableFile(atPath: self.launchPath!) else {
throw CommandError.inAccessibleExecutable(path: self.launchPath!)
guard Files.isExecutableFile(atPath: self.executableURL!.path) else {
throw CommandError.inAccessibleExecutable(path: self.executableURL!.lastPathComponent)
}
launch()
try run()
}
/// Waits until process is finished.
@@ -29,7 +30,7 @@ extension Process {
public func finish() throws {
/// The full path to the executable + all arguments, each one quoted if it contains a space.
func commandAsString() -> String {
let path = self.launchPath ?? ""
let path = self.executableURL?.path ?? ""
return (self.arguments ?? []).reduce(path) { (acc: String, arg: String) in
return acc + " " + ( arg.contains(" ") ? ("\"" + arg + "\"") : arg )
}
@@ -58,7 +59,7 @@ extension Process {
/// - returns: A String containing the hexadecimal representation of the mask,
/// or nil if there is no stdout output
fileprivate func getProcessInfo(_ attr: ProcessAttribute) -> String? {
let attribute = run(bash: "ps --no-headers -q \(self.processIdentifier) -o \(attr.rawValue)").stdout
let attribute = SwiftShell.run(bash: "ps --no-headers -q \(self.processIdentifier) -o \(attr.rawValue)").stdout
return attribute.isEmpty ? nil : attribute
}