Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix error handling in CommandWrapper #44

Merged
merged 1 commit into from
Dec 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Commandant/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct CommandWrapper<ClientError: ErrorType> {
public let usage: () -> CommandantError<ClientError>

/// Creates a command that wraps another.
private init<C: CommandType where C.Options.ClientError == ClientError>(_ command: C) {
private init<C: CommandType where C.ClientError == ClientError, C.Options.ClientError == ClientError>(_ command: C) {
verb = command.verb
function = command.function
run = { (arguments: ArgumentParser) -> Result<(), CommandantError<ClientError>> in
Expand All @@ -50,8 +50,9 @@ public struct CommandWrapper<ClientError: ErrorType> {
}

if let options = options.value {
command.run(options)
return .Success()
return command
.run(options)
.mapError(CommandantError.CommandError)
} else {
return .Failure(options.error!)
}
Expand Down Expand Up @@ -87,7 +88,7 @@ public final class CommandRegistry<ClientError: ErrorType> {
///
/// If another command was already registered with the same `verb`, it will
/// be overwritten.
public func register<C: CommandType where C.Options.ClientError == ClientError>(command: C) {
public func register<C: CommandType where C.ClientError == ClientError, C.Options.ClientError == ClientError>(command: C) {
commandsByVerb[command.verb] = CommandWrapper(command)
}

Expand Down