Refine the no-exit implementaton a little

This commit is contained in:
Samuel Cochran 2013-11-18 10:59:11 +11:00
parent a6c8f680c4
commit 264e912a02
2 changed files with 15 additions and 5 deletions

View File

@ -55,13 +55,17 @@ module MailCatcher extend self
:daemon => !windows?,
:growl => growlnotify?,
:browse => false,
:no_exit => false,
:quit => true,
}
def options
@@options
end
def quittable?
options[:quit]
end
def parse! arguments=ARGV, defaults=@defaults
@@defaults.dup.tap do |options|
OptionParser.new do |parser|
@ -88,8 +92,8 @@ module MailCatcher extend self
options[:http_port] = port
end
parser.on("--no-exit", "Can't exit from the application'") do
options[:no_exit] = true
parser.on("--no-quit", "Don't allow quitting the process") do
options[:quit] = false
end
if mac?
@ -173,7 +177,11 @@ module MailCatcher extend self
# Daemonize, if we should, but only after the servers have started.
if options[:daemon]
EventMachine.next_tick do
puts "*** MailCatcher runs as a daemon by default. Go to the web interface to quit."
if quittable?
puts "*** MailCatcher runs as a daemon by default. Go to the web interface to quit."
else
puts "*** MailCatcher is now running as a daemon that cannot be quit."
end
Process.daemon
end
end

View File

@ -18,9 +18,11 @@ class MailCatcher::Web < Sinatra::Base
end
delete '/' do
unless MailCatcher.options[:no_exit]
if MailCatcher.quittable?
MailCatcher.quit!
status 204
else
status 403
end
end