summary refs log tree commit
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-26 17:50:26 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-26 17:50:26 -0600
commitb5a47e25cf65ad2d87cf9e20474ca372ed91c1b0 (patch)
tree5aada152cbe9583692c0dc15231ff515b6632979
parent43de60320ae895f29918d03b7d43d455a0c4d272 (diff)
downloadrack-b5a47e25cf65ad2d87cf9e20474ca372ed91c1b0.tar.gz
Add --chdir option to rackup
-rw-r--r--lib/rack/server.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/rack/server.rb b/lib/rack/server.rb
index 5f93bc66..e717dc52 100644
--- a/lib/rack/server.rb
+++ b/lib/rack/server.rb
@@ -48,6 +48,10 @@ module Rack
             options[:Port] = port
           }
 
+          opts.on("-c", "--chdir DIR", "Change to dir before starting") { |dir|
+            options[:chdir] = ::File.expand_path(dir)
+          }
+
           opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
             options[:environment] = e
           }
@@ -57,7 +61,7 @@ module Rack
           }
 
           opts.on("-P", "--pid FILE", "file to store PID (default: rack.pid)") { |f|
-            options[:pid] = ::File.expand_path(f)
+            options[:pid] = f
           }
 
           opts.separator ""
@@ -95,12 +99,13 @@ module Rack
 
     def default_options
       {
+        :chdir       => Dir.pwd,
         :environment => "development",
         :pid         => nil,
         :Port        => 9292,
         :Host        => "0.0.0.0",
         :AccessLog   => [],
-        :config   => ::File.expand_path("config.ru")
+        :config      => "config.ru"
       }
     end
 
@@ -130,6 +135,8 @@ module Rack
     end
 
     def start
+      Dir.chdir(options[:chdir])
+
       if options[:debug]
         $DEBUG = true
         require 'pp'