Improving generators runner.

This commit is contained in:
José Valim
2009-06-25 17:34:09 +02:00
parent 915f108d6a
commit 0f1c325f3c
4 changed files with 27 additions and 9 deletions

View File

@@ -7,22 +7,40 @@ if %w(--version -v).include? ARGV.first
exit(0)
end
require File.dirname(__FILE__) + '/../lib/generators'
if ARGV.size == 0
puts "Please select a generator. Options: foo, bar"
return
rails = Rails::Generators.builtin.map do |group, name|
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(', ')}."
exit
elsif ARGV.size == 1
ARGV << "--help"
end
require File.dirname(__FILE__) + '/../lib/generators'
Rails::Generators.builtin.each do |group, name|
require "generators/#{group}/#{name}/#{name}_generator"
end
name = ARGV.shift
name = ARGV.shift
middle = name.sub(':', ':generators:') if name.count(':') == 1
full = "rails:generators:#{name}" if name.count(':') == 0
if klass = Thor::Util.find_by_namespace("rails:generators:#{name}")
if full && klass = Thor::Util.find_by_namespace(full)
klass.start
elsif middle && klass = Thor::Util.find_by_namespace(middle)
klass.start
elsif klass = Thor::Util.find_by_namespace(name)
klass.start

View File

@@ -1,7 +1,7 @@
module Erb
module Generators
class MailerGenerator < Base
argument :actions, :type => :array, :default => []
argument :actions, :type => :array, :default => [], :banner => "method method"
def create_view_folder
empty_directory File.join("app", "views", file_path)

View File

@@ -1,7 +1,7 @@
module Rails
module Generators
class MailerGenerator < NamedBase
argument :actions, :type => :array, :default => []
argument :actions, :type => :array, :default => [], :banner => "method method"
def check_class_collision
class_collisions class_name

View File

@@ -1,7 +1,7 @@
module TestUnit
module Generators
class MailerGenerator < Base
argument :actions, :type => :array, :default => []
argument :actions, :type => :array, :default => [], :banner => "method method"
def create_test_files
template "unit_test.rb", File.join('test', 'unit', class_path, "#{file_name}_test.rb")