Skip to content

Add --open option to launch the web interface on startup #42

Closed
wants to merge 1 commit into from
View
6 Gemfile.lock
@@ -5,6 +5,7 @@ PATH
activesupport (~> 3.0)
eventmachine (~> 0.12)
haml (~> 3.1)
+ launchy (~> 2.1)
mail (~> 2.3)
sinatra (~> 1.2)
skinny (~> 0.2)
@@ -17,6 +18,7 @@ GEM
activesupport (3.2.0)
i18n (~> 0.6)
multi_json (~> 1.0)
+ addressable (2.2.7)
chunky_png (1.2.5)
coffee-script (2.2.0)
coffee-script-source
@@ -47,7 +49,9 @@ GEM
haml (3.1.4)
i18n (0.6.0)
json (1.6.5)
- mail (2.4.1)
+ launchy (2.1.0)
+ addressable (~> 2.2.6)
+ mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
View
17 lib/mail_catcher.rb
@@ -3,6 +3,7 @@
require 'optparse'
require 'rbconfig'
require 'thin'
+require 'launchy'
module MailCatcher
extend ActiveSupport::Autoload
@@ -96,6 +97,10 @@ def parse! arguments=ARGV, defaults=@@defaults
end
end
+ parser.on('-o', '--open', 'Open the web interface in your default browser on startup') do |open|
+ options[:open] = open
+ end
+
parser.on('-v', '--verbose', 'Be more verbose') do
options[:verbose] = true
end
@@ -123,19 +128,27 @@ def run! options=nil
# Get our lion on if asked
MailCatcher::Growl.start if options[:growl]
+ smtp_url = "smtp://#{options[:smtp_ip]}:#{options[:smtp_port]}"
+ http_url = "http://#{options[:http_ip]}:#{options[:http_port]}"
+
# TODO: DRY this up
# Set up an SMTP server to run within EventMachine
rescue_port options[:smtp_port] do
EventMachine.start_server options[:smtp_ip], options[:smtp_port], Smtp
- puts "==> smtp://#{options[:smtp_ip]}:#{options[:smtp_port]}"
+ puts "==> #{smtp_url}"
end
# Let Thin set itself up inside our EventMachine loop
# (Skinny/WebSockets just works on the inside)
rescue_port options[:http_port] do
Thin::Server.start options[:http_ip], options[:http_port], Web
- puts "==> http://#{options[:http_ip]}:#{options[:http_port]}"
+ puts "==> #{http_url}"
+ end
+
+ # Open the web interface if asked
+ if options[:open]
+ Launchy.open(http_url)
end
# Daemonize, if we should, but only after the servers have started.
View
1 mailcatcher.gemspec
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
s.add_dependency "skinny", "~> 0.2"
s.add_dependency "sqlite3", "~> 1.3"
s.add_dependency "thin", "~> 1.2"
+ s.add_dependency "launchy", "~> 2.1"
s.add_development_dependency "coffee-script", "~> 2.2"
s.add_development_dependency "compass", "~> 0.11.1"
Something went wrong with that request. Please try again.