 }
 
 
-func runAgvtool( arguments arguments: [String]! ) -> (Bool, Int32) {
-    let task = NSTask()
+func runAgvtool( arguments: [String]! ) -> (Bool, Int32) {
+    let task = Process()
     task.launchPath = "/usr/bin/agvtool"
     task.arguments = arguments
     task.launch()



func showHelp( errorMessage: String = "" ) -> Void {
    let name = (Process.arguments.first! as String)

    if errorMessage.isEmpty == false {
        print("\(errorMessage)")

}


if CommandLine.arguments.count <= 1 {
    showHelp()
    exit(ExitCodes.Failure.rawValue)
}

let command = CommandLine.arguments[1]
var arguments: [String]

switch ( command.lowercased() ) {
case "bump-build":
    arguments = ["bump", "-all"]
case "set-build":
    if CommandLine.arguments.count >= 3 {
        let buildNumber = CommandLine.arguments[2]
        arguments = ["new-version", "-all", buildNumber]
    } else {
        showHelp(errorMessage: "Missing <build number> parameter.")
        exit(ExitCodes.Failure.rawValue)
    }
case "set-version":
    if CommandLine.arguments.count >= 3 {
        let version = CommandLine.arguments[2]
        arguments = ["new-marketing-version", version]
    } else {
        showHelp(errorMessage: "Missing <version> parameter.")
        exit(ExitCodes.Failure.rawValue)
    }
case "print-current":
    let _ = runAgvtool( arguments: ["mvers"] )
    let _ = runAgvtool( arguments: ["vers"] )
    exit(ExitCodes.Success.rawValue)
case "help":
    showHelp()
    exit(ExitCodes.Failure.rawValue)
default:
    showHelp(errorMessage: "Unrecognized operation specifier \"\(command)\".")
    exit(ExitCodes.Failure.rawValue)
}

