lib/cloud_crowd/command_line.rb in documentcloud-cloud-crowd-0.0.4 vs lib/cloud_crowd/command_line.rb in documentcloud-cloud-crowd-0.0.5

- old
+ new

@@ -12,10 +12,12 @@ # Path to the Daemons gem script which launches workers. WORKER_RUNNER = File.expand_path("#{CC_ROOT}/lib/cloud_crowd/runner.rb") # Command-line banner for the usage message. BANNER = <<-EOS +CloudCrowd is a Ruby & AWS batch processing system, MapReduce style. + Usage: crowd COMMAND OPTIONS COMMANDS: install Install the CloudCrowd configuration files to the specified directory server Start up the central server (requires a database) @@ -43,10 +45,11 @@ # Spin up an IRB session with the CloudCrowd code loaded in, and a database # connection established. The equivalent of Rails' `script/console`. def run_console require 'irb' require 'irb/completion' + require 'pp' load_code connect_to_database IRB.start end @@ -58,13 +61,13 @@ def run_server ensure_config require 'rubygems' rackup_path = File.expand_path("#{@options[:config_path]}/config.ru") if Gem.available? 'thin' - exec "thin -e production -p #{@options[:port]} -R #{rackup_path} start" + exec "thin -e #{@options[:environment]} -p #{@options[:port]} -R #{rackup_path} start" else - exec "rackup -E production -p #{@options[:port]} #{rackup_path}" + exec "rackup -E #{@options[:environment]} -p #{@options[:port]} #{rackup_path}" end end # Load in the database schema to the database specified in 'database.yml'. def run_load_schema @@ -125,11 +128,11 @@ puts `ruby #{WORKER_RUNNER} status` end # Print `crowd` usage. def usage - puts @option_parser + puts "\n#{@option_parser}\n" end private @@ -139,15 +142,15 @@ return if @config_found found = CONFIG_FILES.all? {|f| File.exists? "#{@options[:config_path]}/#{f}" } found ? @config_dir = true : config_not_found end - # Parse all options for all actions. - # TODO: Think about parsing options per sub-command separately. + # Parse all options for all commands. def parse_options @options = { :port => 9173, + :environment => 'production', :config_path => ENV['CLOUD_CROWD_CONFIG'] || '.' } @option_parser = OptionParser.new do |opts| opts.on('-c', '--config PATH', 'path to configuration directory') do |conf_path| @options[:config_path] = conf_path @@ -155,9 +158,12 @@ opts.on('-n', '--num-workers NUM', OptionParser::DecimalInteger, 'number of worker processes') do |num| @options[:num_workers] = num end opts.on('-p', '--port PORT', 'central server port number') do |port_num| @options[:port] = port_num + end + opts.on('-e', '--environment ENV', 'Sinatra environment (code reloading)') do |env| + @options[:environment] = env end opts.on_tail('-v', '--version', 'show version') do load_code puts "CloudCrowd version #{VERSION}" exit \ No newline at end of file