--- dbconsole.rb 2009-10-28 10:56:37.814792166 +0100 +++ dbconsole.rb.new 2009-10-28 11:48:21.346901926 +0100 @@ -3,18 +3,21 @@ require 'optparse' include_password = false +dbpath = nil OptionParser.new do |opt| opt.banner = "Usage: dbconsole [options] [environment]" opt.on("-p", "--include-password", "Automatically provide the password from database.yml") do |v| include_password = true end + opt.on("-y", "--database=path/to/database.yml", "Set the path the database.yml configuration file") { |path| dbpath = path } opt.parse!(ARGV) abort opt.to_s unless (0..1).include?(ARGV.size) end env = ARGV.first || ENV['RAILS_ENV'] || 'development' -unless config = YAML::load(ERB.new(IO.read(RAILS_ROOT + "/config/database.yml")).result)[env] +dbpath ||= RAILS_ROOT + "/config/database.yml" +unless config = YAML::load(ERB.new(IO.read(dbpath)).result)[env] abort "No database is configured for the environment '#{env}'" end