lib/monorail/app.rb in monorail-0.0.1 vs lib/monorail/app.rb in monorail-0.0.3
- old
+ new
@@ -1,6 +1,6 @@
-# $Id: app.rb 2374 2006-04-24 02:51:49Z francis $
+# $Id: app.rb 2406 2006-04-28 16:36:00Z francis $
#
# Monorail::Application
# This runs a monorail system from a command-line binary.
# The binary is generated by rake and invokes us here.
#
@@ -32,93 +32,61 @@
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
+ TITLE = "***Monorail version #{Version}"
+
+ Cmds = {
+ :server => :run_server,
+ :application => :generate_application,
+ :controller => :generate_controller,
+ }
+
def initialize
end
def run
- parse_arguments
- Monorail.new( @options ).run
+ cmd = ARGV.shift
+ if cmd and handler = Cmds[cmd.downcase.intern]
+ send handler
+ else
+ write_cmd_summary
+ end
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
- }
-
-
+ def write_cmd_summary
+ $>.puts TITLE
+ $>.puts
+ $>.puts "Command summary:"
+ Cmds.keys.each {|cmd|
+ $>.puts " monorail #{cmd} [args]"
}
+ $>.puts
+ $>.puts "For more info: monorail <cmd> --help"
+ end
- opts.parse!(ARGV)
+ def generate_application
+ ApplicationGenerator.new.run
+ end
+ def generate_controller
+ ControllerGenerator.new.run
+ end
+
+ def run_server
+ MonorailServer.new.run
end
end # class Application