#!/usr/bin/env ruby require 'rubygems' require 'fileutils' require 'optparse' require 'irt/utils' copy = IRT::Utils.copyright options = {} optparse = OptionParser.new do |opts| opts.banner = < '[ 'y' options[:interactive_eof] = true dirname = File.dirname(path) FileUtils.mkdir_p(dirname) unless File.directory?(dirname) File.open(path, 'w') {|f| f.puts "\n" } # one empty line makes irb of 1.9.2 happy end File.directory?(path) ? Dir.glob(File.join(path, '**/*.irt')) : path end.flatten.compact if files.empty? IRT::Prompter.say_notice 'No *.irt files to run' exit end cmd_format = if File.exists?('./config/environment.rb') && !options[:no_rails] ENV['RAILS_ENV'] = options[:rails_env] if File.exists?('./script/rails') gemfile = File.read('Gemfile') unless gemfile.match(/\bgem\b.+\birt\b/) IRT::Prompter.say_warning %(The Gemfile doesn't look to include any 'gem "irt"' statement.\nIRT will probably not work until you add it!) IRT::Prompter.yes?("Do you want to add irt to your Gemfile?", :hint => '[enter=y|n]', :default => 'y') do File.open('Gemfile', 'a') do |f| f.puts %(gem "irt") end end end 'rails c %s %s %s' elsif File.exists?('./script/console') 'ruby script/console --irb="irt_rails2 %2$s" %1$s %3$s' end else 'irt_irb %s %s' end ENV['IRT_INTERACTIVE_EOF'] = options[:interactive_eof].inspect if options[:interactive_eof] files.each do |file| ENV['IRT_COMMAND'] = sprintf cmd_format, options[:irb_options], file, options[:rails_env] unless system(ENV['IRT_COMMAND']) puts Dye.sgr(:clear) if Dye.color? exit(1) end end