lib/core/shell.rb in cpl-0.4.1 vs lib/core/shell.rb in cpl-0.5.0
- old
+ new
@@ -1,31 +1,53 @@
# frozen_string_literal: true
class Shell
+ class << self
+ attr_reader :tmp_stderr
+ end
+
def self.shell
@shell ||= Thor::Shell::Color.new
end
def self.stderr
@stderr ||= $stderr
end
+ def self.use_tmp_stderr
+ @tmp_stderr = Tempfile.create
+
+ yield
+
+ @tmp_stderr.close
+ @tmp_stderr = nil
+ end
+
+ def self.write_to_tmp_stderr(message)
+ tmp_stderr.write(message)
+ end
+
+ def self.read_from_tmp_stderr
+ tmp_stderr.rewind
+ tmp_stderr.read.strip
+ end
+
def self.color(message, color_key)
shell.set_color(message, color_key)
end
def self.confirm(message)
shell.yes?("#{message} (y/n)")
end
def self.warn(message)
- stderr.puts(color("WARNING: #{message}\n", :yellow))
+ stderr.puts(color("WARNING: #{message}", :yellow))
end
def self.warn_deprecated(message)
- stderr.puts(color("DEPRECATED: #{message}\n", :yellow))
+ stderr.puts(color("DEPRECATED: #{message}", :yellow))
end
def self.abort(message)
- Kernel.abort(color("ERROR: #{message}\n", :red))
+ Kernel.abort(color("ERROR: #{message}", :red))
end
end