Sha256: 27bfc3edd08cbab4fc478b8eb05c20cb8222588d9e40752879f0a3e39ad857f9

Contents?: true

Size: 921 Bytes

Versions: 12

Compression:

Stored size: 921 Bytes

Contents

# 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}", :yellow))
  end

  def self.warn_deprecated(message)
    stderr.puts(color("DEPRECATED: #{message}", :yellow))
  end

  def self.abort(message)
    Kernel.abort(color("ERROR: #{message}", :red))
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cpl-1.1.2.rc.0 lib/core/shell.rb
cpl-1.1.1 lib/core/shell.rb
cpl-1.1.0 lib/core/shell.rb
cpl-1.0.4 lib/core/shell.rb
cpl-1.0.3 lib/core/shell.rb
cpl-1.0.2 lib/core/shell.rb
cpl-1.0.1 lib/core/shell.rb
cpl-1.0.0 lib/core/shell.rb
cpl-0.7.0 lib/core/shell.rb
cpl-0.6.0 lib/core/shell.rb
cpl-0.5.1 lib/core/shell.rb
cpl-0.5.0 lib/core/shell.rb