Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hot patch group fallback capabilities #34

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/Console/Command/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 3 additions & 0 deletions Sources/Console/Console/Console+Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down