# $Id: app.rb 2374 2006-04-24 02:51:49Z francis $ # # Monorail::Application # This runs a monorail system from a command-line binary. # The binary is generated by rake and invokes us here. # #-- # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # require 'ostruct' require 'optparse' module Monorail # TODO, this is not unified with the version string in the Rakefile. Version = "0.0.1" def self.application Application.new end class Application def initialize end def run parse_arguments Monorail.new( @options ).run end def parse_arguments @options = OpenStruct.new @options.host = "127.0.0.1" @options.port = 8090 @options.ssl = false @options.daemon = false @options.rails = nil @options.monorail = nil opts = OptionParser.new {|opts| opts.separator "" opts.separator "Options summary:" opts.on("-a", "--addr IP-address", "Requires the host IP address to listen on", " default: 127.0.0.1") {|addr| @options.host = addr } opts.on("-p", "--port TCP port", "Requires the TCP port to listen on", " default: 8090") {|port| @options.port = port.to_i } opts.on("-s", "--[no-]ssl", "Require SSL (HTTPS)", " default: false") {|ssl| @options.ssl = ssl } opts.on("-d", "--[no-]daemon", "Run in the background", " default: false") {|d| @options.daemon = d } # TODO, wrong, we need one parameter to select the environment, not several. opts.on("--rails [DIR]", "run a rails app in the specified directory", " default: the current directory") {|d| @options.rails = d || "." } opts.on("--monorail [DIR]", "run a monorails app in the specified directory", " default: the current directory") {|d| @options.monorail = d || "." } # Options summary opts.on_tail("-h", "--help", "Show this message") { puts opts exit } # Version opts.on_tail("--version", "Show version") { puts Monorail::Version exit } } opts.parse!(ARGV) end end # class Application end # module Monorail #----------------------