Created
January 16, 2017 14:02
-
-
Save moaible/c21d4e3d370c066f28f12c77f158be04 to your computer and use it in GitHub Desktop.
swift cli system function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // SystemMainAction.swift | |
| // SystemMainAction | |
| // | |
| // Created by moaible on 2017/01/16. | |
| // | |
| // | |
| import Foundation | |
| typealias SystemAction = () -> Void | |
| fileprivate var fulfillAction: SystemAction = { | |
| exit(EXIT_SUCCESS) | |
| } | |
| fileprivate var rejectAction: SystemAction = { | |
| exit(EXIT_FAILURE) | |
| } | |
| typealias SystemMainAction = ( | |
| _ path: String, | |
| _ args: [String], | |
| _ env: [String: String], | |
| _ fulfill: SystemAction, | |
| _ reject: SystemAction) -> Void | |
| func systemMain(action: SystemMainAction) { | |
| action( | |
| ProcessInfo.processInfo.arguments.first ?? "", | |
| Array(ProcessInfo.processInfo.arguments.dropFirst()), | |
| ProcessInfo.processInfo.environment, | |
| fulfillAction, | |
| rejectAction) | |
| RunLoop.main.run() | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage