Sha256: 1c71a988cc97b86260d4e03f8328a57c7ef25741cc6ec0adbe4934b39698b20b

Contents?: true

Size: 1.27 KB

Versions: 29

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Bolt
  class Outputter
    def self.for_format(format, color, verbose, trace, spin)
      case format
      when 'human'
        Bolt::Outputter::Human.new(color, verbose, trace, spin)
      when 'json'
        Bolt::Outputter::JSON.new(color, verbose, trace, false)
      when 'rainbow'
        Bolt::Outputter::Rainbow.new(color, verbose, trace, spin)
      when nil
        raise "Cannot use outputter before parsing."
      end
    end

    def initialize(color, verbose, trace, spin, stream = $stdout)
      @color = color
      @verbose = verbose
      @trace = trace
      @stream = stream
      @spin = spin
    end

    def indent(indent, string)
      indent = ' ' * indent
      string.gsub(/^/, indent.to_s)
    end

    def print_message
      raise NotImplementedError, "print_message() must be implemented by the outputter class"
    end

    def print_error
      raise NotImplementedError, "print_error() must be implemented by the outputter class"
    end

    def start_spin; end

    def stop_spin; end

    def spin
      start_spin
      begin
        yield
      ensure
        stop_spin
      end
    end
  end
end

require 'bolt/outputter/human'
require 'bolt/outputter/json'
require 'bolt/outputter/logger'
require 'bolt/outputter/rainbow'

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
bolt-3.17.0 lib/bolt/outputter.rb
bolt-3.16.1 lib/bolt/outputter.rb
bolt-3.16.0 lib/bolt/outputter.rb
bolt-3.15.0 lib/bolt/outputter.rb
bolt-3.14.1 lib/bolt/outputter.rb
bolt-3.13.0 lib/bolt/outputter.rb
bolt-3.12.0 lib/bolt/outputter.rb
bolt-3.11.0 lib/bolt/outputter.rb
bolt-3.10.0 lib/bolt/outputter.rb
bolt-3.9.2 lib/bolt/outputter.rb
bolt-3.9.1 lib/bolt/outputter.rb
bolt-3.9.0 lib/bolt/outputter.rb
bolt-3.8.1 lib/bolt/outputter.rb
bolt-3.8.0 lib/bolt/outputter.rb
bolt-3.7.1 lib/bolt/outputter.rb
bolt-3.7.0 lib/bolt/outputter.rb
bolt-3.6.1 lib/bolt/outputter.rb
bolt-3.6.0 lib/bolt/outputter.rb
bolt-3.5.0 lib/bolt/outputter.rb
bolt-3.4.0 lib/bolt/outputter.rb