Skip to content

Commit 8669d0a

Browse files
committed
💥 Add alias list to CommandProtocol
1 parent 973ddd3 commit 8669d0a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

‎Sources/Commandant/Command.swift‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public protocol CommandProtocol {
2020
/// `help`).
2121
var verb: String { get }
2222

23+
/// Optional list of additional verbs which can be used to invoke this command.
24+
var aliases: [String] { get }
25+
2326
/// A human-readable, high-level description of what this command is used
2427
/// for.
2528
var function: String { get }
@@ -96,6 +99,10 @@ public final class CommandRegistry<ClientError: Error> {
9699
{
97100
for command in commands {
98101
commandsByVerb[command.verb] = CommandWrapper(command)
102+
// Register command for each additional alias
103+
for alias in command.aliases {
104+
commandsByVerb[alias] = CommandWrapper(command)
105+
}
99106
}
100107
return self
101108
}

‎Sources/Commandant/HelpCommand.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import Foundation
1818
/// let helpCommand = HelpCommand(registry: commands)
1919
/// commands.register(helpCommand)
2020
public struct HelpCommand<ClientError: Error>: CommandProtocol {
21+
2122
public typealias Options = HelpOptions<ClientError>
2223

2324
public let verb = "help"
25+
public let aliases: [String] = []
2426
public let function: String
2527

2628
private let registry: CommandRegistry<ClientError>

0 commit comments

Comments
 (0)