1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/lib/rails/commands/rake/rake_command.rb
Jonathan Hefner 7e54d3bc21 Fix rails new --dev
Follow-up to #38429.

`Rails::Command.invoke` passes arguments through to the appropriate
command class.  However, some command classes were ignoring those
arguments, and instead relying on the contents of ARGV.  In particular,
RakeCommand expected ARGV to contain the arguments necessary to the Rake
task, and no other arguments.  This caused the `webpacker:install` task
to fail when the `--dev` option from `rails new --dev` remained in ARGV.

This commit changes the relevant command classes to not rely on the
previous contents of ARGV.  This commit also adds a missing `require`
for use of `Kernel#silence_warnings`.

Fixes #38459.
2020-02-16 00:44:37 -06:00

51 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module Rails
module Command
class RakeCommand < Base # :nodoc:
extend Rails::Command::Actions
namespace "rake"
class << self
def printing_commands
formatted_rake_tasks.map(&:first)
end
def perform(task, args, config)
require_rake
ARGV.replace([task, *args]) # set up ARGV for Rake
Rake.application.standard_exception_handling do
Rake.application.init("rails")
Rake.application.load_rakefile
Rake.application.top_level
end
end
private
def rake_tasks
require_rake
return @rake_tasks if defined?(@rake_tasks)
require_application!
Rake::TaskManager.record_task_metadata = true
Rake.application.instance_variable_set(:@name, "rails")
load_tasks
@rake_tasks = Rake.application.tasks.select(&:comment)
end
def formatted_rake_tasks
rake_tasks.map { |t| [ t.name_with_args, t.comment ] }
end
def require_rake
require "rake" # Defer booting Rake until we know it's needed.
end
end
end
end
end