Class | Rails::Generator::Scripts::Base |
In: |
vendor/rails/railties/lib/rails_generator/scripts.rb
|
Parent: | Object |
Generator scripts handle command-line invocation. Each script responds to an invoke! class method which handles option parsing and generator invocation.
Run the generator script. Takes an array of unparsed arguments and a hash of parsed arguments, takes the generator as an option or first remaining argument, and invokes the requested command.
# File vendor/rails/railties/lib/rails_generator/scripts.rb, line 17 17: def run(args = [], runtime_options = {}) 18: begin 19: parse!(args.dup, runtime_options) 20: rescue OptionParser::InvalidOption => e 21: # Don't cry, script. Generators want what you think is invalid. 22: end 23: 24: # Generator name is the only required option. 25: unless options[:generator] 26: usage if args.empty? 27: options[:generator] ||= args.shift 28: end 29: 30: # Look up generator instance and invoke command on it. 31: Rails::Generator::Base.instance(options[:generator], args, options).command(options[:command]).invoke! 32: rescue => e 33: puts e 34: puts " #{e.backtrace.join("\n ")}\n" if options[:backtrace] 35: raise SystemExit 36: end
# File vendor/rails/railties/lib/rails_generator/scripts.rb, line 44 44: def usage_message 45: usage = "\nInstalled Generators\n" 46: Rails::Generator::Base.sources.inject({}) do |mem, source| 47: label = source.label.to_s.capitalize 48: mem[label] ||= [] 49: mem[label] |= source.names 50: mem 51: end.each_pair do |label, names| 52: usage << " #{label}: #{names.join(', ')}\n" unless names.empty? 53: end 54: 55: usage << "\nMore are available at http://rubyonrails.org/show/Generators\n 1. Download, for example, login_generator.zip\n 2. Unzip to directory \#{Dir.user_home}/.rails/generators/login\n to use the generator with all your Rails apps\n" 56: 57: if Object.const_defined?(:RAILS_ROOT) 58: usage << " or to \#{File.expand_path(RAILS_ROOT)}/lib/generators/login\n to use with this app only.\n" 59: end 60: 61: usage << " 3. Run generate with no arguments for usage information\n \#{$0} login\n\nGenerator gems are also available:\n 1. gem search -r generator\n 2. gem install login_generator\n 3. \#{$0} login\n\n" 62: return usage 63: end