From 8bce6d543c184f0b94d068076079428b421ae190 Mon Sep 17 00:00:00 2001 From: Ben Chatelain Date: Sun, 23 Aug 2020 20:18:23 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20Add=20alias=20list=20to=20Comman?= =?UTF-8?q?dProtocol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Commandant/Command.swift | 7 +++++++ Sources/Commandant/HelpCommand.swift | 2 ++ 2 files changed, 9 insertions(+) diff --git a/Sources/Commandant/Command.swift b/Sources/Commandant/Command.swift index db5b9ba..438289b 100644 --- a/Sources/Commandant/Command.swift +++ b/Sources/Commandant/Command.swift @@ -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 } @@ -96,6 +99,10 @@ public final class CommandRegistry { { 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 } diff --git a/Sources/Commandant/HelpCommand.swift b/Sources/Commandant/HelpCommand.swift index 0fd3bbf..917f75f 100644 --- a/Sources/Commandant/HelpCommand.swift +++ b/Sources/Commandant/HelpCommand.swift @@ -18,9 +18,11 @@ import Foundation /// let helpCommand = HelpCommand(registry: commands) /// commands.register(helpCommand) public struct HelpCommand: CommandProtocol { + public typealias Options = HelpOptions public let verb = "help" + public let aliases: [String] = [] public let function: String private let registry: CommandRegistry