Permalink
Browse files

Merge pull request #1452 from padrino/padrino-start-accepts-handler-o…

…ptions

Allow padrino start to take handler specific options
  • Loading branch information...
ujifgc committed Oct 16, 2013
2 parents 3e551c9 + 6574209 commit 3c80cac011b124eb468c67e152ad5c542aa40cce
Showing with 37 additions and 1 deletion.
  1. +32 −1 padrino-core/lib/padrino-core/cli/base.rb
  2. +5 −0 padrino-core/lib/padrino-core/server.rb
@@ -18,11 +18,19 @@ class Base < Thor
method_option :daemonize, :type => :boolean, :aliases => "-d", :desc => "Run daemonized in the background."
method_option :pid, :type => :string, :aliases => "-i", :desc => "File to store pid."
method_option :debug, :type => :boolean, :desc => "Set debugging flags."
+ method_option :options, :type => :array, :aliases => "-O", :desc => "--options NAME=VALUE NAME2=VALUE2'. pass VALUE to the server as option NAME. If no VALUE, sets it to true. Run '#{$0} --server_options"
+ method_option :server_options, :type => :boolean, :desc => "Tells the current server handler's options that can be used with --options"
+
def start
prepare :start
require File.expand_path("../adapter", __FILE__)
require File.expand_path('config/boot.rb')
- Padrino::Cli::Adapter.start(options)
+
+ if options[:server_options]
+ puts server_options(options)
+ else
+ Padrino::Cli::Adapter.start(options)
+ end
end
desc "stop", "Stops the Padrino application (alternatively use 'st')."
@@ -124,6 +132,29 @@ def prepare(task)
end
end
+ # https://github.com/rack/rack/blob/master/lib/rack/server.rb\#L100
+ def server_options(options)
+ begin
+ info = []
+ server = Rack::Handler.get(options[:server]) || Rack::Handler.default(options)
+ if server && server.respond_to?(:valid_options)
+ info << ""
+ info << "Server-specific options for #{server.name}:"
+
+ has_options = false
+ server.valid_options.each do |name, description|
+ next if name.to_s.match(/^(Host|Port)[^a-zA-Z]/) # ignore handler's host and port options, we do our own.
+ info << " -O %-21s %s" % [name, description]
+ has_options = true
+ end
+ return "" if !has_options
+ end
+ info.join("\n")
+ rescue NameError
+ return "Warning: Could not find handler specified (#{options[:server] || 'default'}) to determine handler-specific options"
+ end
+ end
+
protected
def self.banner(task=nil, *args)
@@ -31,6 +31,11 @@ def self.start(app, opts={})
FileUtils.mkdir_p(File.dirname(options[:pid]))
end
options[:server] = detect_rack_handler if options[:server].blank?
+ if options[:options].is_a?(Array)
+ parsed_server_options = options.delete(:options).map { |opt| opt.split('=', 2) }.flatten
+ server_options = Hash[*parsed_server_options].symbolize_keys!
+ options.merge!(server_options)
+ end
new(options, app).start
end

0 comments on commit 3c80cac

Please sign in to comment.