Last active
February 5, 2017 14:41
-
-
Save a2/71c40264f58a3ffa635f6a5dffb9a4b2 to your computer and use it in GitHub Desktop.
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
| MainCommand.execute() |
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
| import Guaka | |
| enum MainError: Error, CustomStringConvertible { | |
| case example | |
| var description: String { | |
| switch self { | |
| case .example: | |
| return "This is an example error." | |
| } | |
| } | |
| } | |
| var MainCommand: Command { | |
| let command = Command(usage: "main") | |
| command.run = run(command: command, handler: execute) | |
| return command | |
| } | |
| fileprivate func execute(flags: Flags, args: [String]) throws { | |
| throw MainError.example | |
| } |
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
| import Guaka | |
| func run(command: Command, handler: @escaping (Flags, [String]) throws -> Void) -> Run { | |
| return { flags, args in | |
| do { | |
| try handler(flags, args) | |
| } catch let error as CustomStringConvertible { | |
| command.fail(statusCode: 1, errorMessage: error.description) | |
| } catch { | |
| command.fail(statusCode: 1, errorMessage: String(describing: error)) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment