提交 eb63faaa 编写于 作者: Y yuuji.yaginuma

Revert "Remove deprecated `server` argument from the rails server command"

This reverts commit fa791fb8.

Reason: `server` argument was deprecated in Rails 6.0. Ref: #32058.
上级 9e4283eb
......@@ -2,10 +2,6 @@
*Rafael Mendonça França*
* Remove deprecated `server` argument from the rails server command.
*Rafael Mendonça França*
* Remove deprecated support to old `config.ru` that use the application class as argument of `run`.
*Rafael Mendonça França*
......
......@@ -98,6 +98,8 @@ class ServerCommand < Base # :nodoc:
DEFAULT_PORT = 3000
DEFAULT_PID_PATH = "tmp/pids/server.pid"
argument :using, optional: true
class_option :port, aliases: "-p", type: :numeric,
desc: "Runs Rails on the specified port - defaults to 3000.", banner: :port
class_option :binding, aliases: "-b", type: :string,
......@@ -124,6 +126,7 @@ def initialize(args, local_options, *)
super
@original_options = local_options - %w( --restart )
deprecate_positional_rack_server_and_rewrite_to_option(@original_options)
end
def perform
......@@ -141,7 +144,7 @@ def perform
after_stop_callback = -> { say "Exiting" unless options[:daemon] }
server.start(after_stop_callback)
else
say rack_server_suggestion(options[:using])
say rack_server_suggestion(using)
end
end
end
......@@ -150,7 +153,7 @@ def perform
def server_options
{
user_supplied_options: user_supplied_options,
server: options[:using],
server: using,
log_stdout: log_to_stdout?,
Port: port,
Host: host,
......@@ -259,6 +262,22 @@ def prepare_restart
FileUtils.rm_f(options[:pid]) if options[:restart]
end
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
original_options.concat [ "-u", using ]
else
# Use positional internally to get around Thor's immutable options.
# TODO: Replace `using` occurrences with `options[:using]` after deprecation removal.
@using = options[:using]
end
end
def rack_server_suggestion(server)
if server.in?(RACK_SERVERS)
<<~MSG
......
......@@ -38,6 +38,10 @@ def test_using_server_mistype_without_suggestion
assert_no_match(/Maybe you meant/, output)
end
def test_using_positional_argument_deprecation
assert_match(/DEPRECATION WARNING/, run_command("tin"))
end
def test_using_known_server_that_isnt_in_the_gemfile
assert_match(/Could not load server "unicorn". Maybe you need to the add it to the Gemfile/, run_command("-u", "unicorn"))
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册