def handle_cli_input
if File.exists? options[:app_path]
$: << File.dirname(options[:app_path])
path = File.dirname(options[:app_path])+"/"
else
path = ""
require 'rubygems'
gem(app)
end
$PID_FILE = "/etc/#{app}/#{app}.pid"
OptionParser.new do |opts|
opts.banner = "Usage: #{app} [options]"
opts.on("-c", "--config FILE", "Use config file (default is /etc/#{app}/config.yml)") do |c|
puts "Using config file #{c}"
$CONFIG_FILE = c
end
opts.on("-d", "--daemonize", "Run as a daemon (only when using webrick or mongrel)") do |c|
$DAEMONIZE = true
end
opts.on("-P", "--pid_file FILE", "Use pid file (default is /etc/#{app}/#{app}.pid)") do |c|
if $DAEMONIZE && !File.exists?(c)
puts "Using pid file '#{c}'"
$PID_FILE = c
elsif File.exists?(c)
puts "The pid file already exists. Is #{app} running?\n" +
"You will have to first manually remove the pid file at '#{c}' to start the server as a daemon."
exit 1
else
puts "Not running as daemon. Ignoring pid option"
end
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail("-V", "--version", "Show version number") do
require "#{path}/lib/#{app}/version"
app_mod = @options[:app_module].constantize
puts "#{app}-#{app_mod::VERSION::STRING}"
exit
end
end.parse!
$APP_PATH = options[:app_path]
load "#{path}/lib/#{app}.rb"
end