Add a :quiet option to Pry.start [Fixes #502]
This commit is contained in:
parent
d028beb813
commit
9bf587f234
|
@ -9,6 +9,7 @@ require 'pry/hooks'
|
|||
class Pry
|
||||
# The default hooks - display messages when beginning and ending Pry sessions.
|
||||
DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
|
||||
next if _pry_.quiet?
|
||||
# ensure we're actually in a method
|
||||
file = target.eval('__FILE__')
|
||||
|
||||
|
|
|
@ -46,6 +46,9 @@ class Pry
|
|||
# @return [Fixnum] The number of active Pry sessions.
|
||||
attr_accessor :active_sessions
|
||||
|
||||
# @return [Boolean] Whether Pry sessions are quiet by default.
|
||||
attr_accessor :quiet
|
||||
|
||||
# plugin forwardables
|
||||
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ class Pry
|
|||
attr_accessor :print
|
||||
attr_accessor :exception_handler
|
||||
attr_accessor :input_stack
|
||||
attr_accessor :quiet
|
||||
alias :quiet? :quiet
|
||||
|
||||
attr_accessor :custom_completions
|
||||
|
||||
|
@ -50,6 +52,7 @@ class Pry
|
|||
# @option options [Hash] :hooks The defined hook Procs
|
||||
# @option options [Array<Proc>] :prompt The array of Procs to use for the prompts.
|
||||
# @option options [Proc] :print The Proc to use for the 'print'
|
||||
# @option options [Boolean] :quiet If true, omit the whereami banner when starting.
|
||||
# component of the REPL. (see print.rb)
|
||||
def initialize(options={})
|
||||
refresh(options)
|
||||
|
@ -65,7 +68,7 @@ class Pry
|
|||
def refresh(options={})
|
||||
defaults = {}
|
||||
attributes = [
|
||||
:input, :output, :commands, :print,
|
||||
:input, :output, :commands, :print, :quiet,
|
||||
:exception_handler, :hooks, :custom_completions,
|
||||
:prompt, :memory_size, :input_stack, :extra_sticky_locals
|
||||
]
|
||||
|
|
|
@ -377,4 +377,25 @@ describe "test Pry defaults" do
|
|||
Pry.reset_defaults
|
||||
Pry.color = false
|
||||
end
|
||||
|
||||
describe 'quiet' do
|
||||
it 'should show whereami by default' do
|
||||
output = StringIO.new
|
||||
Pry.start(binding, :input => InputTester.new("1", "exit-all"),
|
||||
:output => output,
|
||||
:hooks => Pry::DEFAULT_HOOKS)
|
||||
|
||||
output.string.should =~ /[w]hereami by default/
|
||||
end
|
||||
|
||||
it 'should hide whereami if quiet is set' do
|
||||
output = StringIO.new
|
||||
Pry.new(:input => InputTester.new("exit-all"),
|
||||
:output => output,
|
||||
:quiet => true,
|
||||
:hooks => Pry::DEFAULT_HOOKS)
|
||||
|
||||
output.string.should == ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue