Use the first unparsed argument as the code or file to run. Closes #6286.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5203 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
643d17ce9e
commit
3c877ecd8a
@ -1,6 +1,6 @@
|
||||
*SVN*
|
||||
|
||||
* script/runner can run files, pass on arguments, and be used as a shebang. #6286 [Tuxie]
|
||||
* script/runner can run files, pass on arguments, and be used as a shebang. #6286 [Tuxie, dlpond]
|
||||
#!/usr/bin/env /path/to/my/app/script/runner
|
||||
# Example: just start using your models as if you are in script/console
|
||||
Product.find(:all).each { |product| product.check_inventory }
|
||||
|
@ -1,6 +1,7 @@
|
||||
require 'optparse'
|
||||
|
||||
options = { :environment => (ENV['RAILS_ENV'] || "development").dup }
|
||||
code_or_file = nil
|
||||
|
||||
ARGV.clone.options do |opts|
|
||||
script_name = File.basename($0)
|
||||
@ -27,19 +28,21 @@
|
||||
opts.separator "-------------------------------------------------------------"
|
||||
end
|
||||
|
||||
opts.parse! rescue retry
|
||||
opts.order! { |o| code_or_file ||= o } rescue retry
|
||||
end
|
||||
|
||||
ARGV.delete(code_or_file)
|
||||
|
||||
ENV["RAILS_ENV"] = options[:environment]
|
||||
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
|
||||
|
||||
require RAILS_ROOT + '/config/environment'
|
||||
|
||||
if ARGV.empty?
|
||||
if code_or_file.nil?
|
||||
$stderr.puts "Run '#{$0} -h' for help."
|
||||
exit 1
|
||||
elsif File.exists?(ARGV.first)
|
||||
eval(File.read(ARGV.shift))
|
||||
elsif File.exists?(code_or_file)
|
||||
eval(File.read(code_or_file))
|
||||
else
|
||||
eval(ARGV.first)
|
||||
eval(code_or_file)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user