From 037561818459e96d145c7dda80fd94b6be95ed2e Mon Sep 17 00:00:00 2001 From: Logan Wright Date: Tue, 18 Apr 2017 17:07:01 +0200 Subject: [PATCH] hot patch group fallback capabilities --- Sources/Console/Command/Group.swift | 4 +++- Sources/Console/Console/Console+Run.swift | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/Console/Command/Group.swift b/Sources/Console/Command/Group.swift index eb311780..f4f9a9b0 100644 --- a/Sources/Console/Command/Group.swift +++ b/Sources/Console/Command/Group.swift @@ -2,10 +2,12 @@ public class Group: Runnable { public var id: String public var commands: [Runnable] public var help: [String] + public var fallback: Command? - public init(id: String, commands: [Runnable], help: [String]) { + public init(id: String, commands: [Runnable], help: [String], fallback: Command? = nil) { self.id = id self.commands = commands self.help = help + self.fallback = fallback } } diff --git a/Sources/Console/Console/Console+Run.swift b/Sources/Console/Console/Console+Run.swift index 41880baa..0347d807 100644 --- a/Sources/Console/Console/Console+Run.swift +++ b/Sources/Console/Console/Console+Run.swift @@ -29,6 +29,9 @@ extension ConsoleProtocol { // group help was requested printHelp(executable: executable, group: group) throw ConsoleError.help + } else if let fallback = group.fallback { + foundCommand = fallback + break } else { // cannot run groups throw ConsoleError.noCommand