#!/usr/bin/env ruby require File.expand_path(File.join(File.dirname(__FILE__), '..', 'castronaut')) $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../vendor/sinatra/lib') $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../vendor/rack/lib') require 'rack' require 'sinatra' require 'optparse' options = {} OptionParser.new do |opts| opts.banner = "Usage: castronaut [Options] {/path/to/config/file}\n" opts.banner += "\t --config: \tStart castronaut using the specified config file.\n" opts.banner += "\t --fresh: \tWrite the castronaut default sample config file to the specified location.\n" opts.banner += "\t --sampledb: \tCreate a sample development database with users for testing.\n" opts.banner += "\t --nginx: \tWrite the sample nginx configuration file to the specified location.\n" opts.on("-h", "--help") do puts opts.banner exit(1) end opts.on("-C", "--config", "Config File") do |c| Castronaut.config = Castronaut::Configuration.load(ARGV[0]) end opts.on("-F", "--fresh", "Directory") do |f| FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'config', 'castronaut.sample.yml'), "#{ARGV[0]}/castronaut.yml") puts "Writing config file to #{ARGV[0]}/castronaut.yml" exit(1) end opts.on("-S", "--sampledb") do puts "Creating development database" Castronaut::Support::Sample.create_sample_database exit(1) end opts.on("-N", "--nginx") do FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'config', 'nginx_vhost.conf'), "#{ARGV[0]}/castronaut.conf") puts "Writing nginx vhost configuration file to #{ARGV[0]}/castronaut.conf" exit(1) end end.parse! unless Castronaut.config $stderr.puts "No configuration file specified. Deafaulting to ./config/castronaut.yml" default_config = File.expand_path("./config/castronaut.yml") if File.exist?(default_config) Castronaut.config = Castronaut::Configuration.load(default_config) else puts "Unable to locate configuration. Currently looking at #{default_config}. You can pass a custom configuration path by using the -C flag." exit(0) end end Sinatra::Application.default_options.merge!( :env => Castronaut.config.environment.to_sym, :run => true, :raise_errors => true, :logging => true, :port => Castronaut.config.respond_to?(:server_port) ? Castronaut.config.server_port : Sinatra::Application.default_options[:port] ) Castronaut.logger.info("Sinatra - Loading app/config.rb") load File.expand_path(File.join(File.dirname(__FILE__), '..', 'app', 'config.rb')) Castronaut.logger.info("Sinatra - Loading app/application.rb") load File.expand_path(File.join(File.dirname(__FILE__), '..', 'app', 'controllers', 'application.rb'))