From 9bf587f2341cc5d677df166eebd83551130d71a4 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sat, 31 Mar 2012 14:18:03 -0700 Subject: [PATCH] Add a :quiet option to Pry.start [Fixes #502] --- lib/pry.rb | 1 + lib/pry/pry_class.rb | 3 +++ lib/pry/pry_instance.rb | 5 ++++- test/test_pry_defaults.rb | 21 +++++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/pry.rb b/lib/pry.rb index e7eb3e1e..68a65034 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -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__') diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 8728ac8b..872b2cb8 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -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 diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 81a3901b..b91793c3 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -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] :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 ] diff --git a/test/test_pry_defaults.rb b/test/test_pry_defaults.rb index 633f7e02..43e5c534 100644 --- a/test/test_pry_defaults.rb +++ b/test/test_pry_defaults.rb @@ -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