Changeset 228

Show
Ignore:
Timestamp:
09/26/2007 17:39:26 (11 months ago)
Author:
zimbatm
Message:

Command-line fixes. Ticket #93 solved.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/bin/camping

    r223 r228  
    1515# Setup paths 
    1616if home = ENV['HOME'] # POSIX 
    17   conf.db = File.join(home, '.camping.db') 
    18   conf.rc = File.join(home, '.campingrc') 
     17  db_path = File.join(home, '.camping.db') 
     18  rc_path = File.join(home, '.campingrc') 
    1919elsif home = ENV['APPDATA'] # MSWIN 
    20   conf.db = File.join(home, 'Camping.db') 
    21   conf.rc = File.join(home, 'Campingrc') 
    22 end 
    23  
    24 # Load configuration if any 
    25 if conf.rc and File.exists?( conf.rc ) 
    26   YAML.load_file(conf.rc).each do |k,v| 
    27     conf.send("#{k}=", v) 
    28   end  
     20  db_path = File.join(home, 'Camping.db') 
     21  rc_path = File.join(home, 'Campingrc') 
    2922end 
    3023 
     
    3831    opts.on("-h", "--host HOSTNAME", "Host for web server to bind to (default is all IPs)") { |conf.host| } 
    3932    opts.on("-p", "--port NUM", "Port for web server (defaults to #{conf.port})") { |conf.port| } 
    40     opts.on("-d", "--database FILE", "Database file (defaults to #{conf.db})") { |conf.db| } 
     33    opts.on("-d", "--database FILE", "SQLite3 database path (defaults to #{db_path ? db_path : '<none>'})") { |db_path| conf.database = {:adapter => 'sqlite3', :database => db_path} } 
    4134    opts.on("-l", "--log FILE", "Start a database log ('-' for STDOUT)") { |conf.log| } 
    42     opts.on("-C", "--console", "Run in console mode with IRB") { conf.server = :console } 
    43     opts.on("-s", "--server NAME", "Server to force (mongrel, webrick, console)") { |s| conf.server = s.to_sym } 
     35    opts.on("-C", "--console", "Run in console mode with IRB") { conf.server = "console" } 
     36    server_list = ["mongrel", "webrick", "console"] 
     37    opts.on("-s", "--server NAME", server_list, "Server to force (#{server_list.join(', ')})") { |conf.server| } 
    4438 
    4539    opts.separator "" 
     
    6155end 
    6256 
    63 opts.parse! ARGV 
     57begin 
     58  opts.parse! ARGV 
     59rescue OptionParser::ParseError => ex 
     60  STDERR.puts "!! #{ex.message}" 
     61  puts "** use `#{File.basename($0)} --help` for more details..." 
     62  exit 1 
     63end 
     64 
    6465if ARGV.length < 1 
    6566    puts opts 
    66     exit 
     67    exit 1 
    6768end 
     69 
     70# Load configuration if any 
     71if rc_path and File.exists?( rc_path ) 
     72  YAML.load_file(rc_path).each do |k,v| 
     73    conf.send("#{k}=", v) unless conf.send(k) 
     74  end  
     75  puts "** conf file #{rc_path} loaded" 
     76end 
     77 
     78# Default db 
     79if conf.database.nil? and db_path 
     80  conf.database = {:adapter => 'sqlite3', :database => db_path} if db_path 
     81end 
     82 
    6883 
    6984# get a copy of the paths to pass to the server 
     
    7186 
    7287# Check that mongrel exists  
    73 if conf.server.nil? || conf.server == :mongrel 
     88if conf.server.nil? || conf.server == "mongrel" 
    7489    begin 
    7590        require 'mongrel' 
    7691        require 'mongrel/camping' 
    77         conf.server = :mongrel 
     92        conf.server = "mongrel" 
    7893    rescue LoadError  
    79         conf.server = :webrick  
     94        puts "!! could not load mongrel. Falling back to webrick." 
     95        conf.server = "webrick" 
    8096    end 
    8197end 
     
    8399require "camping/server/#{conf.server}" 
    84100 
    85 server = Camping::Server.const_get(conf.server.to_s.capitalize).new(conf, paths) 
     101server = Camping::Server.const_get(conf.server.capitalize).new(conf, paths) 
    86102server.start 
  • trunk/lib/camping/reloader.rb

    r225 r228  
    6464            end 
    6565        rescue Exception => e 
    66             puts "!! trouble loading #{title}: [#{e.class}] #{e.message}" 
     66            puts "!! trouble loading #{title.inspect}: [#{e.class}] #{e.message}" 
    6767            puts e.backtrace.join("\n") 
    6868            find_app title 
     
    7474        find_app title 
    7575        unless @klass and @klass.const_defined? :C 
    76             puts "!! trouble loading #{title}: not a Camping app, no #{title.capitalize} module found" 
     76            puts "!! trouble loading #{title.inspect}: not a Camping app, no #{title.capitalize} module found" 
    7777            remove_app 
    7878            return 
     
    8181        Reloader.conditional_connect 
    8282        @klass.create if @klass.respond_to? :create 
    83         puts "!! loaded #{title}" 
     83        puts "** #{title.inspect} app loaded" 
    8484        @klass 
    8585    end 
  • trunk/lib/camping/server.rb

    r207 r228  
    1111  def initialize(conf, paths = []) 
    1212    unless conf.database 
    13       unless conf.db 
    14         raise "!! No home directory found.  Please specify a database file, see --help." 
    15       end 
    16       conf.database = {:adapter => 'sqlite3', :database => conf.db} 
     13      raise "!! No home directory found.  Please specify a database file, see --help." 
    1714    end 
    1815