simple options
authorBlake Mizerany <blake@blake.local>
Wed, 16 Jan 2008 01:30:54 +0000 (15 17:30 -0800)
committerblake@songbirdnest.com <blake@blake.local>
Wed, 16 Jan 2008 01:30:54 +0000 (15 17:30 -0800)
lib/sinatra.rb

index f17ff70..f20fc0f 100644 (file)
@@ -275,10 +275,19 @@ module Sinatra
     def default_options
       self.class.default_options
     end
+
+    def load_options!
+      require 'optparse'
+      OptionParser.new do |op|
+        op.on('-p port') { |port| default_options[:port] = port }
+        op.on('-e env') { |env| default_options[:env] = env }
+      end.parse!(ARGV.dup)
+    end
         
     def initialize
       @events = Hash.new { |hash, key| hash[key] = [] }
       @layouts = Hash.new
+      load_options!
     end
     
     def define_event(method, path, options = {}, &b)