Merge branch 'master' of github.com:sinatra/sinatra
This commit is contained in:
commit
30d4fb468f
|
@ -2192,6 +2192,11 @@ set :protection, :session => true
|
|||
<tt>app_file</tt> setting if not set.
|
||||
</dd>
|
||||
|
||||
<dt>quiet</dt>
|
||||
<dd>
|
||||
Disables logs generated by Sinatra's start and stop commands. `false` by default.
|
||||
</dd>
|
||||
|
||||
<dt>reload_templates</dt>
|
||||
<dd>
|
||||
Whether or not to reload templates between requests. Enabled in development
|
||||
|
@ -2839,7 +2844,7 @@ being [extending the main object](https://github.com/sinatra/sinatra/blob/ca0636
|
|||
Sinatra applications can be run directly:
|
||||
|
||||
```shell
|
||||
ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
|
||||
ruby myapp.rb [-h] [-x] [-q] [-e ENVIRONMENT] [-p PORT] [-o HOST] [-s HANDLER]
|
||||
```
|
||||
|
||||
Options are:
|
||||
|
@ -2850,6 +2855,7 @@ Options are:
|
|||
-o # set the host (default is 0.0.0.0)
|
||||
-e # set the environment (default is development)
|
||||
-s # specify rack server/handler (default is thin)
|
||||
-q # turn on quiet mode for server (default is off)
|
||||
-x # turn on the mutex lock (default is off)
|
||||
```
|
||||
|
||||
|
|
|
@ -1451,7 +1451,7 @@ module Sinatra
|
|||
return unless running?
|
||||
# Use Thin's hard #stop! if available, otherwise just #stop.
|
||||
running_server.respond_to?(:stop!) ? running_server.stop! : running_server.stop
|
||||
$stderr.puts "== Sinatra has ended his set (crowd applauds)" unless handler_name =~/cgi/i
|
||||
$stderr.puts "== Sinatra has ended his set (crowd applauds)" unless supress_messages?
|
||||
set :running_server, nil
|
||||
set :handler_name, nil
|
||||
end
|
||||
|
@ -1533,7 +1533,7 @@ module Sinatra
|
|||
# Starts the server by running the Rack Handler.
|
||||
def start_server(handler, server_settings, handler_name)
|
||||
handler.run(self, server_settings) do |server|
|
||||
unless handler_name =~ /cgi/i
|
||||
unless supress_messages?
|
||||
$stderr.puts "== Sinatra (v#{Sinatra::VERSION}) has taken the stage on #{port} for #{environment} with backup from #{handler_name}"
|
||||
end
|
||||
|
||||
|
@ -1546,6 +1546,10 @@ module Sinatra
|
|||
end
|
||||
end
|
||||
|
||||
def supress_messages?
|
||||
handler_name =~ /cgi/i || quiet
|
||||
end
|
||||
|
||||
def setup_traps
|
||||
if traps?
|
||||
at_exit { quit! }
|
||||
|
@ -1803,6 +1807,7 @@ module Sinatra
|
|||
set :server, %w[HTTP webrick]
|
||||
set :bind, Proc.new { development? ? 'localhost' : '0.0.0.0' }
|
||||
set :port, Integer(ENV['PORT'] && !ENV['PORT'].empty? ? ENV['PORT'] : 4567)
|
||||
set :quiet, false
|
||||
|
||||
ruby_engine = defined?(RUBY_ENGINE) && RUBY_ENGINE
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ module Sinatra
|
|||
op.on('-o addr', "set the host (default is #{bind})") { |val| set :bind, val }
|
||||
op.on('-e env', 'set the environment (default is development)') { |val| set :environment, val.to_sym }
|
||||
op.on('-s server', 'specify rack server/handler (default is thin)') { |val| set :server, val }
|
||||
op.on('-q', 'turn on quiet mode (default is off)') { set :quiet, true }
|
||||
op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
|
||||
}.parse!(ARGV.dup)
|
||||
end
|
||||
|
|
|
@ -53,4 +53,18 @@ class ServerTest < Minitest::Test
|
|||
it "falls back on the next server handler when not found" do
|
||||
@app.run! :server => %w[foo bar mock]
|
||||
end
|
||||
|
||||
describe "Quiet mode" do
|
||||
it "sends data to stderr when server starts and stops" do
|
||||
@app.run!
|
||||
assert_match(/\=\= Sinatra/, $stderr.string)
|
||||
end
|
||||
|
||||
context "when quiet mode is activated" do
|
||||
it "does not generate Sinatra start and stop messages" do
|
||||
@app.run! quiet: true
|
||||
refute_match(/\=\= Sinatra/, $stderr.string)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue