Skip to content

Commit

Permalink
💥 Add alias list to CommandProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
phatblat committed Aug 24, 2020
1 parent ea060fb commit 8951818
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/Commandant/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public protocol CommandProtocol {
/// `help`).
var verb: String { get }

/// Optional list of additional verbs which can be used to invoke this command.
var aliases: [String] { get }

/// A human-readable, high-level description of what this command is used
/// for.
var function: String { get }
Expand Down Expand Up @@ -96,6 +99,10 @@ public final class CommandRegistry<ClientError: Error> {
{
for command in commands {
commandsByVerb[command.verb] = CommandWrapper(command)
// Register command for each additional alias
for alias in command.aliases {
commandsByVerb[alias] = CommandWrapper(command)
}
}
return self
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/Commandant/HelpCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import Foundation
/// let helpCommand = HelpCommand(registry: commands)
/// commands.register(helpCommand)
public struct HelpCommand<ClientError: Error>: CommandProtocol {

public typealias Options = HelpOptions<ClientError>

public let verb = "help"
public let aliases: [String] = []
public let function: String

private let registry: CommandRegistry<ClientError>
Expand Down

0 comments on commit 8951818

Please sign in to comment.