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

View File

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