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

[CommandRegistry] Return self from register(_:) for method chaining #111

Merged
merged 2 commits into from
Aug 14, 2017
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
17 changes: 12 additions & 5 deletions Sources/Commandant/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,19 @@ public final class CommandRegistry<ClientError: Error> {

public init() {}

/// Registers the given command, making it available to run.
/// Registers the given commands, making those available to run.
///
/// If another command was already registered with the same `verb`, it will
/// be overwritten.
public func register<C: CommandProtocol>(_ command: C) where C.ClientError == ClientError, C.Options.ClientError == ClientError {
commandsByVerb[command.verb] = CommandWrapper(command)
/// If another commands were already registered with the same `verb`s, those
/// will be overwritten.
@discardableResult
public func register<C: CommandProtocol>(_ commands: C...)
-> CommandRegistry
where C.ClientError == ClientError, C.Options.ClientError == ClientError
{
for command in commands {
commandsByVerb[command.verb] = CommandWrapper(command)
}
return self
}

/// Runs the command corresponding to the given verb, passing it the given
Expand Down