Permalink
Browse files

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
  • Loading branch information...
1 parent 643d17c commit 3c877ecd8a4ee2a0b27f30ff557b400d567540a6 @jeremy jeremy committed Sep 29, 2006
Showing with 9 additions and 6 deletions.
  1. +1 −1 railties/CHANGELOG
  2. +8 −5 railties/lib/commands/runner.rb
View
@@ -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

0 comments on commit 3c877ec

Please sign in to comment.