Skip to content

Commit

Permalink
[Group] Allow custom unknown command handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Oct 31, 2015
1 parent 9be0581 commit 1fde582
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Commander/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class Group : CommandType {

var commands = [SubCommand]()

// When set, allows you to override the default unknown command behaviour
public var unknownCommand: ((name: String, parser: ArgumentParser) throws -> ())?

/// Create a new group
public init() {}

Expand Down Expand Up @@ -80,6 +83,8 @@ public class Group : CommandType {
} catch let error as Help {
throw error.reraise(name)
}
} else if let unknownCommand = unknownCommand {
try unknownCommand(name: name, parser: parser)
} else {
throw GroupError.UnknownCommand(name)
}
Expand Down

0 comments on commit 1fde582

Please sign in to comment.