Changeset 228 for trunk/bin/camping
- Timestamp:
- 09/26/2007 17:39:26 (14 months ago)
- Files:
-
- 1 modified
-
trunk/bin/camping (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/camping
r223 r228 15 15 # Setup paths 16 16 if 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') 19 19 elsif 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') 29 22 end 30 23 … … 38 31 opts.on("-h", "--host HOSTNAME", "Host for web server to bind to (default is all IPs)") { |conf.host| } 39 32 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} } 41 34 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| } 44 38 45 39 opts.separator "" … … 61 55 end 62 56 63 opts.parse! ARGV 57 begin 58 opts.parse! ARGV 59 rescue OptionParser::ParseError => ex 60 STDERR.puts "!! #{ex.message}" 61 puts "** use `#{File.basename($0)} --help` for more details..." 62 exit 1 63 end 64 64 65 if ARGV.length < 1 65 66 puts opts 66 exit 67 exit 1 67 68 end 69 70 # Load configuration if any 71 if 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" 76 end 77 78 # Default db 79 if conf.database.nil? and db_path 80 conf.database = {:adapter => 'sqlite3', :database => db_path} if db_path 81 end 82 68 83 69 84 # get a copy of the paths to pass to the server … … 71 86 72 87 # Check that mongrel exists 73 if conf.server.nil? || conf.server == :mongrel88 if conf.server.nil? || conf.server == "mongrel" 74 89 begin 75 90 require 'mongrel' 76 91 require 'mongrel/camping' 77 conf.server = :mongrel92 conf.server = "mongrel" 78 93 rescue LoadError 79 conf.server = :webrick 94 puts "!! could not load mongrel. Falling back to webrick." 95 conf.server = "webrick" 80 96 end 81 97 end … … 83 99 require "camping/server/#{conf.server}" 84 100 85 server = Camping::Server.const_get(conf.server. to_s.capitalize).new(conf, paths)101 server = Camping::Server.const_get(conf.server.capitalize).new(conf, paths) 86 102 server.start
