提交 ec55e59e 编写于 作者: J José Valim

Updated commands.

上级 776220e1
...@@ -10,33 +10,9 @@ end ...@@ -10,33 +10,9 @@ end
require File.dirname(__FILE__) + '/../lib/generators' require File.dirname(__FILE__) + '/../lib/generators'
if ARGV.size == 0 if ARGV.size == 0
rails = Rails::Generators.builtin.map do |group, name| Rails::Generators.help
name if group == "rails"
end
rails.compact!
rails.sort!
others = Rails::Generators.builtin.map do |group, name|
"#{group}:#{name}" unless rails.include?(name)
end.compact
others.sort!
puts "Please select a generator."
puts "Builtin: #{rails.join(', ')}."
puts "Others: #{others.join(', ')}." unless others.empty?
exit exit
end end
Rails::Generators.builtin.each do |group, name|
require "generators/#{group}/#{name}/#{name}_generator"
end
name = ARGV.shift name = ARGV.shift
Rails::Generators.invoke name, ARGV, :invoke
if klass = Rails::Generators.find_by_namespace(name, "rails")
ARGV << "--help" if klass.arguments.any? { |a| a.required? } && ARGV.empty?
klass.start
else
puts "Could not find generator #{name}."
end
require "#{RAILS_ROOT}/config/environment" require "#{RAILS_ROOT}/config/environment"
require 'rails_generator' require 'generators'
require 'rails_generator/scripts/destroy'
ARGV.shift if ['--help', '-h'].include?(ARGV[0]) if ARGV.size == 0
Rails::Generator::Scripts::Destroy.new.run(ARGV) Rails::Generators.help
exit
end
name = ARGV.shift
Rails::Generators.invoke name, ARGV, :revoke
require "#{RAILS_ROOT}/config/environment" require "#{RAILS_ROOT}/config/environment"
require 'rails_generator' require 'generators'
require 'rails_generator/scripts/generate'
ARGV.shift if ['--help', '-h'].include?(ARGV[0]) if ARGV.size == 0
Rails::Generator::Scripts::Generate.new.run(ARGV) Rails::Generators.help
exit
end
name = ARGV.shift
Rails::Generators.invoke name, ARGV, :invoke
require "#{RAILS_ROOT}/config/environment" require "#{RAILS_ROOT}/config/environment"
require 'rails_generator' require 'generators'
require 'rails_generator/scripts/update'
Rails::Generator::Scripts::Update.new.run(ARGV) if ARGV.size == 0
Rails::Generators.help
exit
end
name = ARGV.shift
Rails::Generators.invoke name, ARGV, :skip
...@@ -25,7 +25,7 @@ def self.builtin ...@@ -25,7 +25,7 @@ def self.builtin
# #
# ==== Examples # ==== Examples
# #
# lookup_by_namespace :webrat, :rails, :integration # find_by_namespace :webrat, :rails, :integration
# #
# Will search for the following generators: # Will search for the following generators:
# #
...@@ -36,7 +36,7 @@ def self.builtin ...@@ -36,7 +36,7 @@ def self.builtin
# #
# Finally, it deals with one kind of shortcut: # Finally, it deals with one kind of shortcut:
# #
# lookup_by_namespace "test_unit:model" # find_by_namespace "test_unit:model"
# #
# It will search for generators at: # It will search for generators at:
# #
...@@ -51,12 +51,46 @@ def self.find_by_namespace(name, base=nil, context=nil) ...@@ -51,12 +51,46 @@ def self.find_by_namespace(name, base=nil, context=nil)
attempts << name attempts << name
attempts.each do |namespace| attempts.each do |namespace|
klass, task = Thor::Util.find_by_namespace(namespace) klass = Thor::Util.find_by_namespace(namespace)
return klass if klass return klass if klass
end end
nil nil
end end
# Show help message with available generators.
#
def self.help
rails = Rails::Generators.builtin.map do |group, name|
name if group == "rails"
end
rails.compact!
rails.sort!
puts "Please select a generator."
puts "Builtin: #{rails.join(', ')}."
# TODO Show others after lookup is implemented
# puts "Others: #{others.join(', ')}."
end
# Receives a namespace, arguments and the behavior to invoke the generator.
# It's used as the default entry point for generate, destroy and update
# commands.
#
def self.invoke(namespace, args=ARGV, behavior=:invoke)
# Load everything right now ...
builtin.each do |group, name|
require "generators/#{group}/#{name}/#{name}_generator"
end
if klass = find_by_namespace(namespace, "rails")
args << "--help" if klass.arguments.any? { |a| a.required? } && args.empty?
klass.start args, :behavior => behavior
else
puts "Could not find generator #{namespace}."
end
end
end end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册