Merge branch 'benjolitz-additional_options_closure'
This commit is contained in:
commit
212ea8707d
3 changed files with 20 additions and 1 deletions
|
@ -28,4 +28,19 @@ describe "Config" do
|
||||||
config.add_handler CustomTestHandler.new
|
config.add_handler CustomTestHandler.new
|
||||||
config.handlers.size.should eq(5)
|
config.handlers.size.should eq(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "adds custom options" do
|
||||||
|
config = Kemal.config
|
||||||
|
ARGV.push("--test")
|
||||||
|
ARGV.push("FOOBAR")
|
||||||
|
test_option = nil
|
||||||
|
|
||||||
|
config.extra_options do |parser|
|
||||||
|
parser.on("--test TEST_OPTION", "Test an option") do |opt|
|
||||||
|
test_option = opt
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Kemal::CLI.new
|
||||||
|
test_option.should eq("FOOBAR")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,6 +34,7 @@ module Kemal
|
||||||
puts opts
|
puts opts
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
@config.extra_options.try &.call(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Kemal
|
||||||
@server : HTTP::Server?
|
@server : HTTP::Server?
|
||||||
|
|
||||||
property host_binding, ssl, port, env, public_folder, logging,
|
property host_binding, ssl, port, env, public_folder, logging,
|
||||||
always_rescue, serve_static, server
|
always_rescue, serve_static, server, extra_options
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@host_binding = "0.0.0.0"
|
@host_binding = "0.0.0.0"
|
||||||
|
@ -68,6 +68,9 @@ module Kemal
|
||||||
HANDLERS.insert(0, @logger.not_nil!)
|
HANDLERS.insert(0, @logger.not_nil!)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extra_options(&@extra_options : OptionParser ->)
|
||||||
|
end
|
||||||
|
|
||||||
private def setup_error_handler
|
private def setup_error_handler
|
||||||
if @always_rescue
|
if @always_rescue
|
||||||
@error_handler ||= Kemal::CommonExceptionHandler.new
|
@error_handler ||= Kemal::CommonExceptionHandler.new
|
||||||
|
|
Loading…
Reference in a new issue