make dbconsole honor environment when options specified #213

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+5 −3
Split
@@ -11,6 +11,8 @@
module Rails
class DBConsole
+ MODES = ['html', 'list', 'line', 'column']
+
def self.start(app)
new(app).start
end
@@ -28,8 +30,8 @@ def start
include_password = true
end
- opt.on("--mode [MODE]", ['html', 'list', 'line', 'column'],
- "Automatically put the sqlite3 database in the specified mode (html, list, line, column).") do |mode|
+ opt.on("--mode [MODE]", MODES,
+ "Automatically put the sqlite3 database in the specified mode (#{MODES.join(', ')}).") do |mode|
options['mode'] = mode
end
@@ -118,6 +120,6 @@ def find_cmd(*commands)
end
# Has to set the RAILS_ENV before config/application is required
-if ARGV.first && !ARGV.first.index("-") && env = ARGV.first
+if (arg = ARGV.last) && !arg.index("-") && !Rails::DBConsole::MODES.include?(arg) && env = arg
ENV['RAILS_ENV'] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
end