#!/usr/bin/env ruby

require 'rubygems'
require 'rails-installer'

installer = RailsInstaller.new('.')

unless installer.is_valid_rails_directory?
  STDERR.puts "Please run this command from the root of a valid Rails project"
  exit(1)
end

restore_file = ARGV[0]

unless restore_file and File.exists?(restore_file) and restore_file =~ /\.yml$/
  puts "Usage:"
  puts "  rails-restore FILENAME"
  puts ""
  puts "  Restores the database contents from FILENAME into the database defined"
  puts "  in 'config/database.yml'.  FILENAME should be generated by the "
  puts "  'rails-backup' command."
end

installer.restore_database restore_file
