Sha256: 12425b5bd2b559dd304cecdb2afbf12532d4f78fc8360fa78d7fb759099a39f0

Contents?: true

Size: 1.73 KB

Versions: 16

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module Jive
  class BatchRunner
    attr_reader :runner, :stdout

    def initialize(runner: Runner.new, stdout: $stdout)
      @runner = runner
      @stdout = stdout
    end

    def run(tasks)
      stream_output_for(runner, tasks)
      stdout.puts "==================================================="
      print_result_for(runner)
    end

    private

    def stream_output_for(runner, tasks)
      runner.run(tasks) do |command, &run|
        stdout.puts
        stdout.puts "$ #{command.join(" ")}"
        result = run.call
        stdout.print result.stdout
        stdout.print result.stderr
        stdout.puts "==> Finished in #{result.duration} seconds"
        stdout.puts
      end
    end

    def print_result_for(runner)
      if runner.all_success_and_clean?
        stdout.puts "Passed successfully."
        0
      elsif runner.all_success?
        stdout.puts "Passed successfully, but we have warnings:"
        stdout.puts
        emit_warnings_for(runner)
        2
      else
        stdout.puts "Something failed:"
        emit_warnings_for(runner)
        emit_errors_for(runner)
        1
      end
    end

    def emit_warnings_for(runner)
      runner.warned_results.each do |result|
        stdout.puts
        stdout.puts "**** #{result.command.join(" ")} had the following warning(s):"
        stdout.puts
        stdout.puts result.stderr
        stdout.puts
      end
    end

    def emit_errors_for(runner)
      runner.failed_results.each do |result|
        stdout.puts
        stdout.puts "**** #{result.command.join(" ")} failed with the following error(s):"
        stdout.puts
        stdout.puts result.stdout
        stdout.puts result.stderr
        stdout.puts
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
jive-0.7.0 lib/jive/batch_runner.rb
jive-0.6.0 lib/jive/batch_runner.rb
jive-0.5.0 lib/jive/batch_runner.rb
jive-0.4.4 lib/jive/batch_runner.rb
jive-0.4.3 lib/jive/batch_runner.rb
jive-0.4.2 lib/jive/batch_runner.rb
jive-0.4.1 lib/jive/batch_runner.rb
jive-0.4.0 lib/jive/batch_runner.rb
jive-0.3.3 lib/jive/batch_runner.rb
jive-0.3.2 lib/jive/batch_runner.rb
jive-0.3.1 lib/jive/batch_runner.rb
jive-0.3.0 lib/jive/batch_runner.rb
jive-0.2.3 lib/jive/batch_runner.rb
jive-0.2.2 lib/jive/batch_runner.rb
jive-0.2.1 lib/jive/batch_runner.rb
jive-0.2.0 lib/jive/batch_runner.rb