diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-02 11:08:07 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-02 11:08:07 +0200 |
commit | ec55e59e993d6c39c6ba8d57d4ef6d270ee8c14f (patch) | |
tree | ee34b3c3bb05c313a160dd51aa2aaab6238c4619 /railties/lib/generators.rb | |
parent | 776220e1e2a4e523b87511d8bb665f2dcc4981d4 (diff) | |
download | rails-ec55e59e993d6c39c6ba8d57d4ef6d270ee8c14f.tar.gz rails-ec55e59e993d6c39c6ba8d57d4ef6d270ee8c14f.tar.bz2 rails-ec55e59e993d6c39c6ba8d57d4ef6d270ee8c14f.zip |
Updated commands.
Diffstat (limited to 'railties/lib/generators.rb')
-rw-r--r-- | railties/lib/generators.rb | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb index fd7d3c9580..8814f6e800 100644 --- a/railties/lib/generators.rb +++ b/railties/lib/generators.rb @@ -25,7 +25,7 @@ module Rails # # ==== Examples # - # lookup_by_namespace :webrat, :rails, :integration + # find_by_namespace :webrat, :rails, :integration # # Will search for the following generators: # @@ -36,7 +36,7 @@ module Rails # # 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: # @@ -51,12 +51,46 @@ module Rails attempts << name attempts.each do |namespace| - klass, task = Thor::Util.find_by_namespace(namespace) + klass = Thor::Util.find_by_namespace(namespace) return klass if klass end nil 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 |