Skip to content

Instantly share code, notes, and snippets.

@a2
Last active February 5, 2017 14:41
Show Gist options
  • Select an option

  • Save a2/71c40264f58a3ffa635f6a5dffb9a4b2 to your computer and use it in GitHub Desktop.

Select an option

Save a2/71c40264f58a3ffa635f6a5dffb9a4b2 to your computer and use it in GitHub Desktop.
MainCommand.execute()
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
}
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