aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/commands/server/server_command.rb47
-rw-r--r--railties/test/commands/server_test.rb17
2 files changed, 42 insertions, 22 deletions
diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb
index cf17f0ef12..2c5440d9ec 100644
--- a/railties/lib/rails/commands/server/server_command.rb
+++ b/railties/lib/rails/commands/server/server_command.rb
@@ -97,10 +97,6 @@ module Rails
end
end
- def restart_command
- "bin/rails server #{ARGV.join(' ')}"
- end
-
def use_puma?
server.to_s == "Rack::Handler::Puma"
end
@@ -132,16 +128,18 @@ module Rails
desc: "Specifies the Rack server used to run the application (thin/puma/webrick).", banner: :name
class_option :pid, aliases: "-P", type: :string, default: DEFAULT_PID_PATH,
desc: "Specifies the PID file."
- class_option "dev-caching", aliases: "-C", type: :boolean, default: nil,
+ class_option :dev_caching, aliases: "-C", type: :boolean, default: nil,
desc: "Specifies whether to perform caching in development."
- class_option "restart", type: :boolean, default: nil, hide: true
- class_option "early_hints", type: :boolean, default: nil, desc: "Enables HTTP/2 early hints."
+ class_option :restart, type: :boolean, default: nil, hide: true
+ class_option :early_hints, type: :boolean, default: nil, desc: "Enables HTTP/2 early hints."
+ class_option :log_to_stdout, type: :boolean, default: nil, optional: true,
+ desc: "Whether to log to stdout. Enabled by default in development when not daemonized."
- def initialize(args = [], local_options = {}, config = {})
- @original_options = local_options
+ def initialize(args, local_options, *)
super
- @using = deprecated_positional_rack_server(using) || options[:using]
- @log_stdout = options[:daemon].blank? && (options[:environment] || Rails.env) == "development"
+
+ @original_options = local_options - %w( --restart )
+ deprecate_positional_rack_server_and_rewrite_to_option(@original_options)
end
def perform
@@ -169,7 +167,7 @@ module Rails
{
user_supplied_options: user_supplied_options,
server: using,
- log_stdout: @log_stdout,
+ log_stdout: log_to_stdout?,
Port: port,
Host: host,
DoNotReverseLookup: true,
@@ -177,7 +175,7 @@ module Rails
environment: environment,
daemonize: options[:daemon],
pid: pid,
- caching: options["dev-caching"],
+ caching: options[:dev_caching],
restart_cmd: restart_command,
early_hints: early_hints
}
@@ -210,7 +208,7 @@ module Rails
name = :Port
when :binding
name = :Host
- when :"dev-caching"
+ when :dev_caching
name = :caching
when :daemonize
name = :daemon
@@ -252,13 +250,19 @@ module Rails
end
def restart_command
- "bin/rails server #{using} #{@original_options.join(" ")} --restart"
+ "bin/rails server #{@original_options.join(" ")} --restart"
end
def early_hints
options[:early_hints]
end
+ def log_to_stdout?
+ options.fetch(:log_to_stdout) do
+ options[:daemon].blank? && environment == "development"
+ end
+ end
+
def pid
File.expand_path(options[:pid])
end
@@ -271,14 +275,19 @@ module Rails
FileUtils.rm_f(options[:pid]) if options[:restart]
end
- def deprecated_positional_rack_server(value)
- if value
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ def deprecate_positional_rack_server_and_rewrite_to_option(original_options)
+ if using
+ ActiveSupport::Deprecation.warn(<<~MSG)
Passing the Rack server name as a regular argument is deprecated
and will be removed in the next Rails version. Please, use the -u
option instead.
MSG
- value
+
+ original_options.concat [ "-u", using ]
+ else
+ # Use positional internally to get around Thor's immutable options.
+ # TODO: Replace `using` occurences with `options[:using]` after deprecation removal.
+ @using = options[:using]
end
end
diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb
index e7a56b3e6d..e5b1da6ea4 100644
--- a/railties/test/commands/server_test.rb
+++ b/railties/test/commands/server_test.rb
@@ -143,10 +143,22 @@ class Rails::Command::ServerCommandTest < ActiveSupport::TestCase
options = parse_arguments(args)
assert_equal true, options[:log_stdout]
+ args = ["-e", "development", "-d"]
+ options = parse_arguments(args)
+ assert_equal false, options[:log_stdout]
+
args = ["-e", "production"]
options = parse_arguments(args)
assert_equal false, options[:log_stdout]
+ args = ["-e", "development", "--no-log-to-stdout"]
+ options = parse_arguments(args)
+ assert_equal false, options[:log_stdout]
+
+ args = ["-e", "production", "--log-to-stdout"]
+ options = parse_arguments(args)
+ assert_equal true, options[:log_stdout]
+
with_rack_env "development" do
args = []
options = parse_arguments(args)
@@ -245,10 +257,9 @@ class Rails::Command::ServerCommandTest < ActiveSupport::TestCase
args = %w(-p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C)
ARGV.replace args
- options = parse_arguments(args)
- expected = "bin/rails server -p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C --restart"
+ expected = "bin/rails server -p 4567 -b 127.0.0.1 -c dummy_config.ru -d -e test -P tmp/server.pid -C --restart"
- assert_equal expected, options[:restart_cmd]
+ assert_equal expected, parse_arguments(args)[:restart_cmd]
ensure
ARGV.replace original_args
end