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

- old
+ new

@@ -1,6 +1,69 @@ #!/usr/bin/env ruby require 'rack' +require 'optparse' require 'web-facter' +require 'parseconfig' -Rack::Server.new(:app => WebFacter::App.new, :Port => 9294, :daemonize => true).start +options = {} + +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 + puts opts + exit + 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 +rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument + puts $!.to_s + puts optparse + exit +rescue Errno::EACCES + puts $!.to_s + exit +end