Skip to content
This repository has been archived by the owner on Feb 28, 2021. It is now read-only.

Commit

Permalink
Added code to WSOC::Runner.
Browse files Browse the repository at this point in the history
* Renamed bin/wsoc to bin/wsoc_server, to match the README.
  • Loading branch information
postmodern committed Dec 31, 2009
1 parent b020c21 commit 28c0bdb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
File renamed without changes.
63 changes: 63 additions & 0 deletions lib/wsoc/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,78 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

require 'wsoc/app'

require 'optparse'

module WSOC
class Runner

# Default host to run the WSOC server on
DEFAULT_HOST = 'localhost'

# Default port to run the WSOC server on
DEFAULT_PORT = 8080

# Host to run the WSOC server on
attr_reader :host

# Port to run the WSOC server on
attr_reader :port

def initialize
@host = DEFAULT_HOST
@port = DEFAULT_PORT
@handler = nil
end

def Runner.start(args=ARGV)
runner = self.new()
runner.run(*args)
end

def run(*args)
optparse(*args)

App.run!(
:env => :production,
:host => @host,
:port => @port,
:server => @handler
)
end

protected

def optparse(*args)
opts = OptionParser.new

opts.banner = "usage: #{$0} [options]"

opts.on('-H','--host HOST',"The host to run the server on","Default: #{DEFAULT_HOST}") do |host|
@host = host
end

opts.on('-p','--port PORT',"The port to run the server on","Default: #{DEFAULT_PORT}") do |port|
@port = port.to_i
end

opts.on('--s','--server NAME','Rack handler to run the server under') do |handler|
@handler = handler
end

opts.on('-h','--help','Display the help output') do
puts opts
exit
end

begin
opts.parse!(args)
rescue OptionParser::InvalidOption => e
STDERR.puts e.message
STDERR.puts opts
exit -1
end
end

end
Expand Down

0 comments on commit 28c0bdb

Please sign in to comment.