Class: CircleCI::CLI::Printer::StepPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/circleci/cli/printer/step_printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(steps, pretty: true) ⇒ StepPrinter

Returns a new instance of StepPrinter.



7
8
9
10
# File 'lib/circleci/cli/printer/step_printer.rb', line 7

def initialize(steps, pretty: true)
  @steps = steps
  @pretty = pretty
end

Instance Method Details

#to_sObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/circleci/cli/printer/step_printer.rb', line 12

def to_s # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  if @pretty
    Terminal::Table.new do |t|
      @steps
        .group_by(&:type)
        .each do |key, steps|
        t << :separator
        t << [{ value: key.green, alignment: :center, colspan: 2 }]
        steps.each { |s| print_actions(t, s) }
      end
    end.to_s
  else
    @steps.group_by(&:type).map do |_, steps|
      steps.map do |step|
        step.actions.map do |a|
          "#{colorize_by_status(a.name.slice(0..120), a.status)}\n#{"#{a.log}\n" if a.failed? && a.log}"
        end
      end.flatten.join('')
    end.join("\n")
  end
end