bin/web-facter in web-facter-0.0.3 vs bin/web-facter in web-facter-0.1.0

- old
+ new

@@ -1,31 +1,27 @@ #!/usr/bin/env ruby require 'rack' require 'optparse' require 'web-facter' -require 'parseconfig' -options = {} +options = {:daemonize => true, :port => 9294, :config => false} optparse = OptionParser.new do |opts| opts.banner = 'Usage: web-facter [options] ...' opts.separator '' opts.separator 'Configuration options:' - options[:daemonize] = true opts.on( '--no-daemonize', "Don't daemonize the web server process") do |_| options[:daemonize] = false end - options[:port] = 9294 opts.on( '-p', '--port PORT', 'The port to run web-facter on') do |port| options[:port] = port end - options[:config] = false opts.on( '-c', '--config FILE', 'The file to load with configuration options') do |file| options[:config] = file end opts.on_tail('-h', '--help', 'Display this screen') do @@ -34,32 +30,10 @@ end end begin optparse.parse! - - application = WebFacter::App.new - - daemonize = options[:daemonize] - port = options[:port] - - if options[:config] - conf = ParseConfig.new(options[:config]) - - if conf.get_value('password') - application = Rack::Auth::Basic.new(application) do |username, password| - username_check = conf.get_value('username') ? conf.get_value('username') == username : true - password_check = conf.get_value('password') == password - username_check && password_check - end - application.realm = 'Web Facter' - end - - port = conf.get_value('port') ? conf.get_value('port') : port - daemonize = conf.get_value('daemonize') ? conf.get_value('daemonize') == "true" : daemonize - end - - Rack::Server.new(:app => application, :Port => port, :daemonize => daemonize).start + WebFacter::App.run!(options) rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument puts $!.to_s puts optparse exit rescue Errno::EACCES