Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport Send user_supplied_options to server #28321

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 32 additions & 8 deletions railties/lib/rails/commands/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ class Options

def parse!(args)
args, options = args.dup, {}
options[:user_supplied_options] = []
options[:user_supplied_options] << :Host if ENV["Host"]
options[:user_supplied_options] << :Port if ENV["PORT"]

option_parser(options).parse! args

options[:user_supplied_options].uniq!
options[:log_stdout] = options[:daemonize].blank? && (options[:environment] || Rails.env) == "development"
options[:server] = args.shift
options
Expand All @@ -25,21 +29,42 @@ def option_parser(options)
OptionParser.new do |opts|
opts.banner = "Usage: rails server [mongrel, thin etc] [options]"
opts.on("-p", "--port=port", Integer,
"Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v }
"Runs Rails on the specified port.", "Default: 3000") { |v|
options[:user_supplied_options] << :Port
options[:Port] = v
}
opts.on("-b", "--binding=IP", String,
"Binds Rails to the specified IP.", "Default: localhost") { |v| options[:Host] = v }
"Binds Rails to the specified IP.", "Default: localhost") { |v|
options[:user_supplied_options] << :Host
options[:Host] = v
}
opts.on("-c", "--config=file", String,
"Uses a custom rackup configuration.") { |v| options[:config] = v }
opts.on("-d", "--daemon", "Runs server as a Daemon.") { options[:daemonize] = true }
"Uses a custom rackup configuration.") { |v|
options[:user_supplied_options] << :config
options[:config] = v
}
opts.on("-d", "--daemon", "Runs server as a Daemon.") {
options[:user_supplied_options] << :daemonize
options[:daemonize] = true
}
opts.on("-e", "--environment=name", String,
"Specifies the environment to run this server under (test/development/production).",
"Default: development") { |v| options[:environment] = v }
"Default: development") { |v|
options[:user_supplied_options] << :environment
options[:environment] = v
}
opts.on("-P", "--pid=pid", String,
"Specifies the PID file.",
"Default: tmp/pids/server.pid") { |v| options[:pid] = v }
"Default: tmp/pids/server.pid") { |v|
options[:user_supplied_options] << :pid
options[:pid] = v
}
opts.on("-C", "--[no-]dev-caching",
"Specifies whether to perform caching in development.",
"true or false") { |v| options[:caching] = v }
"true or false") { |v|
options[:user_supplied_options] << :caching
options[:caching] = v
}

opts.separator ""

Expand Down Expand Up @@ -100,7 +125,6 @@ def default_options
end

private

def setup_dev_caching
if options[:environment] == "development"
Rails::DevCaching.enable_by_argument(options[:caching])
Expand Down
8 changes: 8 additions & 0 deletions railties/test/commands/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ def test_log_stdout
end
end

def test_records_user_supplied_options
server_options = Rails::Server::Options.new.parse!(["-p", "3001"])
assert_equal [:Port], server_options[:user_supplied_options]

server_options = Rails::Server::Options.new.parse!(["--port", "3001"])
assert_equal [:Port], server_options[:user_supplied_options]
end

def test_default_options
server = Rails::Server.new
old_default_options = server.default_options
Expand Down