Skip to content

Commit ab80aa4

Browse files
authored
Merge pull request #111 from Carthage/chain-register
[CommandRegistry] Return self from `register(_:)` for method chaining
2 parents 077845e + fed2d54 commit ab80aa4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Sources/Commandant/Command.swift

+12-5
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,19 @@ public final class CommandRegistry<ClientError: Error> {
8686

8787
public init() {}
8888

89-
/// Registers the given command, making it available to run.
89+
/// Registers the given commands, making those available to run.
9090
///
91-
/// If another command was already registered with the same `verb`, it will
92-
/// be overwritten.
93-
public func register<C: CommandProtocol>(_ command: C) where C.ClientError == ClientError, C.Options.ClientError == ClientError {
94-
commandsByVerb[command.verb] = CommandWrapper(command)
91+
/// If another commands were already registered with the same `verb`s, those
92+
/// will be overwritten.
93+
@discardableResult
94+
public func register<C: CommandProtocol>(_ commands: C...)
95+
-> CommandRegistry
96+
where C.ClientError == ClientError, C.Options.ClientError == ClientError
97+
{
98+
for command in commands {
99+
commandsByVerb[command.verb] = CommandWrapper(command)
100+
}
101+
return self
95102
}
96103

97104
/// Runs the command corresponding to the given verb, passing it the given

0 commit comments

Comments
 (0)