aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/cmd')
-rw-r--r--Library/Homebrew/cmd/link.rb28
1 files changed, 25 insertions, 3 deletions
diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb
index d882ee7ec..09d16c782 100644
--- a/Library/Homebrew/cmd/link.rb
+++ b/Library/Homebrew/cmd/link.rb
@@ -1,4 +1,5 @@
module Homebrew extend self
+
def link
raise KegUnspecifiedError if ARGV.named.empty?
@@ -9,9 +10,30 @@ module Homebrew extend self
end
ARGV.kegs.each do |keg|
- print "Linking #{keg}... "
- puts if ARGV.verbose?
- puts "#{keg.link} symlinks created"
+ print "Linking #{keg}... " do
+ puts if ARGV.verbose?
+ puts "#{keg.link} symlinks created"
+ end
+ end
+ end
+
+ private
+
+ # Allows us to ensure a puts happens before the block exits so that if say,
+ # an exception is thrown, its output starts on a new line.
+ def print str, &block
+ Kernel.print str
+ puts_capture = Class.new do
+ def self.puts str
+ $did_puts = true
+ Kernel.puts str
+ end
end
+
+ puts_capture.instance_eval &block
+
+ ensure
+ puts unless $did_puts
end
+
end