Add naive cli command router
This commit is contained in:
17
src/cli/command_router.cr
Normal file
17
src/cli/command_router.cr
Normal file
@ -0,0 +1,17 @@
|
||||
class CLI::CommandRouter
|
||||
def initialize
|
||||
@mappings = [] of {String, Proc(Nil)}
|
||||
end
|
||||
|
||||
def add(route, &block)
|
||||
@mappings.push({route, block})
|
||||
end
|
||||
|
||||
def handle(command)
|
||||
@mappings.each do |i|
|
||||
if i[0] == command
|
||||
i[1].call
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user