lib/cloud_crowd/command_line.rb in documentcloud-cloud-crowd-0.1.1 vs lib/cloud_crowd/command_line.rb in documentcloud-cloud-crowd-0.2.0
- old
+ new
@@ -47,11 +47,11 @@
def run_console
require 'irb'
require 'irb/completion'
require 'pp'
load_code
- connect_to_database
+ connect_to_database(true)
IRB.start
end
# Convenience command for quickly spinning up the central server. More
# sophisticated deployments, load-balancing across multiple app servers,
@@ -79,23 +79,23 @@
end
# Load in the database schema to the database specified in 'database.yml'.
def run_load_schema
load_code
- connect_to_database
+ connect_to_database(false)
require 'cloud_crowd/schema.rb'
end
# Install the required CloudCrowd configuration files into the specified
# directory, or the current one.
def run_install
require 'fileutils'
install_path = ARGV.shift || '.'
FileUtils.mkdir_p install_path unless File.exists?(install_path)
install_file "#{CC_ROOT}/config/config.example.yml", "#{install_path}/config.yml"
- install_file "#{CC_ROOT}/config/database.example.yml", "#{install_path}/database.yml"
install_file "#{CC_ROOT}/config/config.example.ru", "#{install_path}/config.ru"
+ install_file "#{CC_ROOT}/config/database.example.yml", "#{install_path}/database.yml"
install_file "#{CC_ROOT}/actions", "#{install_path}/actions", true
end
# Print `crowd` usage.
def usage
@@ -147,22 +147,27 @@
CloudCrowd.configure("#{@options[:config_path]}/config.yml")
end
# Establish a connection to the central server's database. Not all commands
# require this.
- def connect_to_database
+ def connect_to_database(validate_schema)
require 'cloud_crowd/models'
- CloudCrowd.configure_database("#{@options[:config_path]}/database.yml")
+ CloudCrowd.configure_database("#{@options[:config_path]}/database.yml", validate_schema)
end
# Exit with an explanation if the configuration files couldn't be found.
def config_not_found
- puts "`crowd` can't find the CloudCrowd configuration directory. Please either run `crowd` from inside of the configuration directory, or use `crowd -c path/to/config`"
+ puts "`crowd` can't find the CloudCrowd configuration directory. Please use `crowd -c path/to/config`, or run `crowd` from inside of the configuration directory itself."
exit(1)
end
- # Install a file and log the installation.
+ # Install a file and log the installation. If we're overwriting a file,
+ # offer a chance to back out.
def install_file(source, dest, is_dir=false)
+ if File.exists?(dest)
+ print "#{dest} already exists. Overwrite it? (yes/no) "
+ return unless ['y', 'yes', 'ok'].include? gets.chomp.downcase
+ end
is_dir ? FileUtils.cp_r(source, dest) : FileUtils.cp(source, dest)
puts "installed #{dest}"
end
end
\ No newline at end of file