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 #29146 to 5-1-stable #30597

Merged
merged 1 commit into from
Sep 14, 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
11 changes: 9 additions & 2 deletions railties/lib/rails/commands/server/server_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,16 @@ def server_options
def user_supplied_options
@user_supplied_options ||= begin
# Convert incoming options array to a hash of flags
# ["-p", "3001", "-c", "foo"] # => {"-p" => true, "-c" => true}
# ["-p3001", "-C", "--binding", "127.0.0.1"] # => {"-p"=>true, "-C"=>true, "--binding"=>true}
user_flag = {}
@original_options.each_with_index { |command, i| user_flag[command] = true if i.even? }
@original_options.each do |command|
if command.to_s.start_with?("--")
option = command.split("=")[0]
user_flag[option] = true
elsif command =~ /\A(-.)/
user_flag[Regexp.last_match[0]] = true
end
end

# Collect all options that the user has explicitly defined so we can
# differentiate them from defaults
Expand Down
6 changes: 6 additions & 0 deletions railties/test/commands/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def test_records_user_supplied_options

server_options = parse_arguments(["--port", 3001])
assert_equal [:Port], server_options[:user_supplied_options]

server_options = parse_arguments(["-p3001", "-C", "--binding", "127.0.0.1"])
assert_equal [:Port, :Host, :caching], server_options[:user_supplied_options]

server_options = parse_arguments(["--port=3001"])
assert_equal [:Port], server_options[:user_supplied_options]
end

def test_default_options
Expand Down