Skip to content

Commit 1fde582

Browse files
committed
[Group] Allow custom unknown command handler
1 parent 9be0581 commit 1fde582

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Commander/Group.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class Group : CommandType {
4949

5050
var commands = [SubCommand]()
5151

52+
// When set, allows you to override the default unknown command behaviour
53+
public var unknownCommand: ((name: String, parser: ArgumentParser) throws -> ())?
54+
5255
/// Create a new group
5356
public init() {}
5457

@@ -80,6 +83,8 @@ public class Group : CommandType {
8083
} catch let error as Help {
8184
throw error.reraise(name)
8285
}
86+
} else if let unknownCommand = unknownCommand {
87+
try unknownCommand(name: name, parser: parser)
8388
} else {
8489
throw GroupError.UnknownCommand(name)
8590
}

0 commit comments

Comments
 (0)