Make pathForExecutable an inner function.

This commit is contained in:
Kare Morstol
2015-10-06 18:25:08 +02:00
parent b7dab5666e
commit 6ff91b2b57
+13 -12
View File
@@ -44,19 +44,20 @@ public protocol ShellRunnable {
extension ShellRunnable {
/**
If `executable` is not a path and a path for an executable file of that name can be found, return that path.
Otherwise just return `executable`.
*/
private func pathForExecutable (executable: String) -> String {
guard !executable.characters.contains("/") else {
return executable
}
let path = self.run("/usr/bin/which", executable)
return path.isEmpty ? executable : path
}
func createTask (executable: String, args: [String]) -> NSTask {
/**
If `executable` is not a path and a path for an executable file of that name can be found, return that path.
Otherwise just return `executable`.
*/
func pathForExecutable (executable: String) -> String {
guard !executable.characters.contains("/") else {
return executable
}
let path = self.run("/usr/bin/which", executable)
return path.isEmpty ? executable : path
}
let task = NSTask()
task.arguments = args
task.launchPath = pathForExecutable(executable)