 }
 
 let arguments = Process.arguments
-var defaults = Keychain(suiteName: "qc")
+var defaults = Keychain(identifier: "qc")
 
 let usage =
   "usage: qc \t\t\t\tConnect to the saved network\n" +

  "tell application \"System Events\" to tell process \"Cisco AnyConnect Secure Mobility Client\"\n" +
  "if button \"Disconnect\" of window 1 exists then\n" +
    "click button \"Disconnect\" of window 1\n" +
    "return\n" +
  "end if\n" +
  "tell combo box 1 of window 1 to set value to \"%@\"\n" +
  "click button \"Connect\" of window 1\n" +

  }
}

func recognizeEvent(descriptor: NSAppleEventDescriptor) -> Result<String, QCError> {
    return descriptor.int32Value == 1 ? .Success("Disconnected! 🍻") : .Success("Connected! 👍")
}

func connect(password: String?, toNetwork network: String?) -> Result<String, QCError> {
  return validatePassword(password) &&& validateNetwork(network)
    >>- createScript
    >>- executeScript
    >>- recognizeEvent
}

func eval<T>(result: Result<T, QCError>, success: T -> () = { print($0) }, fail: QCError -> () = printErrorAndExit) {
  switch result {
  case let .Success(res): success(res)
  case let .Failure(error): fail(error)
  }
}

