Sha256: 44ab93ac3ce1650a242ef40161e6b75016de6e0b5e26d4dcb65b0f6f02d54de4
Contents?: true
Size: 1.39 KB
Versions: 5
Compression:
Stored size: 1.39 KB
Contents
# frozen_string_literal: true require "English" require "io/console" require "paint" require "pty" class CheckAll TASKNAMES = %i[rubocop spec steep:check yard:check].freeze LINE = Paint["-" * (IO.console or raise).winsize[1], :bold] TITLE_TEMPLATE = Paint["\n#{LINE}\nExecute: %<command>s\n#{LINE}\n\n", :bold] attr_reader :failed_commands def self.call new.call end def initialize @failed_commands = [] end def call TASKNAMES.map { |taskname| Thread.new(taskname, &executor) }.each(&:join) output_result end private def executor lambda do |taskname| command = "bundle exec rake #{taskname}" outputs = [] outputs << format(TITLE_TEMPLATE, command:) # Use `PTY.spawn` to get colorized outputs of each command. PTY.spawn(command) do |reader, writer, pid| writer.close while (output = reader.gets) outputs << output end Process.wait(pid) end failed_commands << command unless $CHILD_STATUS&.success? puts outputs.join end end def output_result puts "" puts LINE puts Paint["Result", :bold] puts LINE if failed_commands.empty? puts Paint["\nAll checks are OK.", :green, :bold] else puts Paint["\nChecks failed!!\n", :red, :bold] puts failed_commands.map { |command| " - #{command}" }.join("\n") abort "" end end end
Version data entries
5 entries across 5 versions & 1 rubygems