   "end repeat\n" +
   "keystroke \"%@\"\n" +
   "click button \"OK\" of window 1\n" +
+  "repeat until button \"Disconnect\" of window 1 exists\n" +
+  "end repeat\n" +
+  "return 0\n" +
 "end tell\n"
 
 func printErrorAndExit(error: ErrorType) {

  }
}

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

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)
  }
}


  print("Settings cleared! 🖖")
}
else if arguments.hasOption(Option.network) {
  eval(connect(defaults.password, toNetwork: arguments.argumentForOption(Option.network)))
}
else if arguments.count > 1 {
  let option = arguments[1]
  printErrorAndExit(QCError.UnknownOption(option))
}
else {
  eval(connect(defaults.password, toNetwork: defaults.network))
}

exit(EXIT_SUCCESS)
