提交 d5bd4b25 编写于 作者: K Kasper Timm Hansen

Run engine commands through command infrastructure.

上级 6813edc7
module Rails
module Command
module Actions
private
# Change to the application's path if there is no config.ru file in current directory.
# This allows us to run `rails server` from other directories, but still get
# the main config.ru and properly set the tmp directory.
def set_application_directory!
Dir.chdir(File.expand_path("../../", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
# Change to the application's path if there is no config.ru file in current directory.
# This allows us to run `rails server` from other directories, but still get
# the main config.ru and properly set the tmp directory.
def set_application_directory!
Dir.chdir(File.expand_path("../../", APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
end
if defined?(ENGINE_PATH)
def require_application_and_environment!
require ENGINE_PATH
end
def load_tasks
Rake.application.init("rails")
Rake.application.load_rakefile
end
def load_generators
engine = ::Rails::Engine.find(ENGINE_ROOT)
Rails::Generators.namespace = engine.railtie_namespace
engine.load_generators
end
else
def require_application_and_environment!
require APP_PATH
Rails.application.require_environment!
end
def load_tasks
Rails.application.load_tasks
end
def load_generators
Rails.application.load_generators
end
end
end
end
end
......@@ -15,6 +15,11 @@ class Error < Thor::Error # :nodoc:
include Actions
class << self
# Returns true when the app is a Rails engine.
def engine?
defined?(ENGINE_ROOT)
end
# Tries to get the description from a USAGE file one folder above the command
# root.
def desc(usage = nil, description = nil)
......
Usage: bin/rails COMMAND [args] [options]
<% if engine? %>
The common Rails commands available for engines are:
generate Generate new code (short-cut alias: "g")
destroy Undo code generated with "generate" (short-cut alias: "d")
test Run tests (short-cut alias: "t")
All commands can be run with -h for more information.
If you want to run any commands that need to be run in context
of the application, like `bin/rails server` or `bin/rails console`,
you should do it from the application's directory (typically test/dummy).
<% else %>
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
......@@ -11,6 +22,6 @@ The most common rails commands are:
new application called MyApp in "./my_app"
All commands can be run with -h (or --help) for more information.
<% end %>
In addition to those commands, there are:
module Rails
module Command
class RakeCommand < Base
extend Rails::Command::Actions
namespace "rake"
class << self
......@@ -27,12 +29,12 @@ def rake_tasks
return @rake_tasks if defined?(@rake_tasks)
ActiveSupport::Deprecation.silence do
Rails::Command.require_application_and_environment!
require_application_and_environment!
end
Rake::TaskManager.record_task_metadata = true
Rake.application.instance_variable_set(:@name, "rails")
Rails.application.load_tasks
load_tasks
@rake_tasks = Rake.application.tasks.select(&:comment)
end
......
require "rails/engine/commands_tasks"
ARGV << "--help" if ARGV.empty?
require "rails/command"
aliases = {
"g" => "generate",
......@@ -11,4 +9,4 @@
command = ARGV.shift
command = aliases[command] || command
Rails::Engine::CommandsTasks.new(ARGV).run_command!(command)
Rails::Command.invoke command, ARGV
......@@ -26,7 +26,7 @@ def command_whitelist
def help_message
<<-EOT.strip_heredoc
Usage: rails COMMAND [ARGS]
Usage: bin/rails COMMAND [ARGS]
The common Rails commands available for engines are:
generate Generate new code (short-cut alias: "g")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册