aboutsummaryrefslogtreecommitdiffstats
path: root/railties/bin/gen
blob: a6363edd543302f13fd6caca7b3be7a8dee6a9b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.dirname(__FILE__) + '/../lib/ruby_version_check'
Signal.trap("INT") { puts; exit }

require File.dirname(__FILE__) + '/../lib/rails/version'
if %w(--version -v).include? ARGV.first
  puts "Rails #{Rails::VERSION::STRING}"
  exit(0)
end

require File.dirname(__FILE__) + '/../lib/generators'

if ARGV.size == 0
  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(', ')}." unless others.empty?

  exit
elsif ARGV.size == 1
  ARGV << "--help"
end

Rails::Generators.builtin.each do |group, name|
  require "generators/#{group}/#{name}/#{name}_generator"
end

name = ARGV.shift

if klass = Rails::Generators.find_by_namespace(name, "rails")
  klass.start
else
  puts "Could not find generator #{name}."
end