diff options
Diffstat (limited to 'lib/bundler/vendor/thor/shell/basic.rb')
-rw-r--r--[-rwxr-xr-x] | lib/bundler/vendor/thor/shell/basic.rb | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/lib/bundler/vendor/thor/shell/basic.rb b/lib/bundler/vendor/thor/shell/basic.rb index b227b5f4..c8411d3d 100755..100644 --- a/lib/bundler/vendor/thor/shell/basic.rb +++ b/lib/bundler/vendor/thor/shell/basic.rb @@ -11,6 +11,21 @@ class Thor @base, @padding = nil, 0 end + # Mute everything that's inside given block + # + def mute + @mute = true + yield + ensure + @mute = false + end + + # Check if base is muted + # + def mute? + @mute + end + # Sets the output padding, not allowing less than zero values. # def padding=(value) @@ -24,7 +39,7 @@ class Thor # def ask(statement, color=nil) say("#{statement} ", color) - $stdin.gets.strip + stdin.gets.strip end # Say (print) something to the user. If the sentence ends with a whitespace @@ -41,11 +56,11 @@ class Thor spaces = " " * padding if force_new_line - $stdout.puts(spaces + message) + stdout.puts(spaces + message) else - $stdout.print(spaces + message) + stdout.print(spaces + message) end - $stdout.flush + stdout.flush end # Say a status with the given color and appends the message. Since this @@ -61,15 +76,15 @@ class Thor status = status.to_s.rjust(12) status = set_color status, color, true if color - $stdout.puts "#{status}#{spaces}#{message}" - $stdout.flush + stdout.puts "#{status}#{spaces}#{message}" + stdout.flush end # Make a question the to user and returns true if the user replies "y" or # "yes". # def yes?(statement, color=nil) - ask(statement, color) =~ is?(:yes) + !!(ask(statement, color) =~ is?(:yes)) end # Make a question the to user and returns true if the user replies "n" or @@ -113,7 +128,7 @@ class Thor end sentence = truncate(sentence, options[:truncate]) if options[:truncate] - $stdout.puts sentence + stdout.puts sentence end end @@ -139,9 +154,9 @@ class Thor paras.each do |para| para.split("\n").each do |line| - $stdout.puts line.insert(0, " " * ident) + stdout.puts line.insert(0, " " * ident) end - $stdout.puts unless para == paras.last + stdout.puts unless para == paras.last end end @@ -180,12 +195,12 @@ class Thor end # Called if something goes wrong during the execution. This is used by Thor - # internally and should not be used inside your scripts. If someone went + # internally and should not be used inside your scripts. If something went # wrong, you can always raise an exception. If you raise a Thor::Error, it # will be rescued and wrapped in the method below. # def error(statement) - $stderr.puts statement + stderr.puts statement end # Apply color to the given string with optional bold. Disabled in the @@ -197,6 +212,18 @@ class Thor protected + def stdout + $stdout + end + + def stdin + $stdin + end + + def stderr + $stderr + end + def is?(value) #:nodoc: value = value.to_s @@ -229,7 +256,7 @@ HELP end def quiet? #:nodoc: - base && base.options[:quiet] + mute? || (base && base.options[:quiet]) end # This code was copied from Rake, available under MIT-LICENSE |