0001    //
0002    //  CommandExecutor.swift
0003    //  CommandExecutor
0004    //
0005    //  Created by Omar Abdelhafith on 05/11/2015.
0006    //  Copyright © 2015 Omar Abdelhafith. All rights reserved.
0007    //
0008    
0009    import Foundation
0010    
0011    
0012    typealias ExecutorReturnValue
CommandExecutor.swift:18
  class func execute(commandParts: [String]) -> ExecutorReturnValue {
CommandExecutor.swift:25
  func execute(commandParts: [String]) -> ExecutorReturnValue
CommandExecutor.swift:30
  func execute(commandParts: [String]) -> ExecutorReturnValue {
CommandExecutor.swift:41
  func execute(commandParts: [String]) -> ExecutorReturnValue  {
CommandExecutor.swift:64
  func execute(commandParts: [String]) -> ExecutorReturnValue  {
CommandExecutor.swift:86
  func execute(commandParts: [String]) -> ExecutorReturnValue {
= (status: Int, standardOutput: TaskPipe, standardError: TaskPipe) 0013 0014 class CommandExecutor
Runner.swift:79
        return execute(commandParts, withExecutor: CommandExecutor.currentTaskExecutor)
{ 0015 0016 static var currentTaskExecutor
CommandExecutor.swift:19
    return currentTaskExecutor.execute(commandParts)
Runner.swift:79
        return execute(commandParts, withExecutor: CommandExecutor.currentTaskExecutor)
: TaskExecutor = ActualTaskExecutor() 0017 0018 class func execute(commandParts: [String]) -> ExecutorReturnValue { 0019 return currentTaskExecutor.execute(commandParts) 0020 } 0021 } 0022 0023 0024 protocol TaskExecutor
CommandExecutor.swift:16
  static var currentTaskExecutor: TaskExecutor = ActualTaskExecutor()
CommandExecutor.swift:28
class DryTaskExecutor: TaskExecutor {
CommandExecutor.swift:39
class ActualTaskExecutor: TaskExecutor {
CommandExecutor.swift:62
class InteractiveTaskExecutor: TaskExecutor {
CommandExecutor.swift:72
class DummyTaskExecutor: TaskExecutor {
Runner.swift:82
    private class func execute(commandParts: [String], withExecutor executor: TaskExecutor) -> RunResults {
{ 0025 func execute
CommandExecutor.swift:19
    return currentTaskExecutor.execute(commandParts)
Runner.swift:83
        let (status, stdoutPipe, stderrPipe) = executor.execute(commandParts)
(commandParts: [String]) -> ExecutorReturnValue 0026 } 0027 0028 class DryTaskExecutor
Runner.swift:71
        return execute(commandParts, withExecutor: DryTaskExecutor())
: TaskExecutor { 0029 0030 func execute(commandParts: [String]) -> ExecutorReturnValue { 0031 let command = commandParts.joinWithSeparator(" ") 0032 PromptSettings.print("Executed command '\(command)'") 0033 return (0, 0034 Dryipe(dataToReturn: "".dataUsingEncoding(NSUTF8StringEncoding)!), 0035 Dryipe(dataToReturn: "".dataUsingEncoding(NSUTF8StringEncoding)!)) 0036 } 0037 } 0038 0039 class ActualTaskExecutor
CommandExecutor.swift:16
  static var currentTaskExecutor: TaskExecutor = ActualTaskExecutor()
: TaskExecutor { 0040 0041 func execute(commandParts: [String]) -> ExecutorReturnValue { 0042 let task = NSTask() 0043 0044 // let commands = ["-c", "\"\(commandParts.joinWithSeparator(" "))\""] 0045 // print(commands) 0046 // task.launchPath = "/usr/bin/env" 0047 task.launchPath = "/usr/bin/env" 0048 // task.arguments = commandParts 0049 0050 let stdoutPipe = NSPipe() 0051 let stderrPipe = NSPipe() 0052 0053 task.standardOutput = stdoutPipe 0054 task.standardError = stderrPipe 0055 task.launch() 0056 task.waitUntilExit() 0057 0058 return (Int(task.terminationStatus), stdoutPipe, stderrPipe) 0059 } 0060 } 0061 0062 class InteractiveTaskExecutor
Runner.swift:75
        return execute(commandParts, withExecutor: InteractiveTaskExecutor())
: TaskExecutor { 0063 0064 func execute(commandParts: [String]) -> ExecutorReturnValue { 0065 let result = system(commandParts.joinWithSeparator(" ")) 0066 0067 let emptyPipe = Dryipe(dataToReturn: "".dataUsingEncoding(NSUTF8StringEncoding)!) 0068 return (Int(result), emptyPipe, emptyPipe) 0069 } 0070 } 0071 0072 class DummyTaskExecutor: TaskExecutor { 0073 0074 var commandsExecuted
CommandExecutor.swift:88
    commandsExecuted.append(command)
: [String] = [] 0075 let statusCodeToReturn
CommandExecutor.swift:81
    statusCodeToReturn = status
CommandExecutor.swift:90
    return (statusCodeToReturn,
: Int 0076 0077 let errorToReturn
CommandExecutor.swift:83
    errorToReturn = error
CommandExecutor.swift:92
      Dryipe(dataToReturn: errorToReturn.dataUsingEncoding(NSUTF8StringEncoding)!))
: String 0078 let outputToReturn
CommandExecutor.swift:82
    outputToReturn = output
CommandExecutor.swift:91
      Dryipe(dataToReturn: outputToReturn.dataUsingEncoding(NSUTF8StringEncoding)!),
: String 0079 0080 init(status: Int, output: String, error: String) { 0081 statusCodeToReturn = status 0082 outputToReturn = output 0083 errorToReturn = error 0084 } 0085 0086 func execute(commandParts: [String]) -> ExecutorReturnValue { 0087 let command = commandParts.joinWithSeparator(" ") 0088 commandsExecuted.append(command) 0089 0090 return (statusCodeToReturn, 0091 Dryipe(dataToReturn: outputToReturn.dataUsingEncoding(NSUTF8StringEncoding)!), 0092 Dryipe(dataToReturn: errorToReturn.dataUsingEncoding(NSUTF8StringEncoding)!)) 0093 } 0094 } 0095