2012-08-16 04:10:54 +02:00
|
|
|
module Mutant
|
|
|
|
class Reporter
|
|
|
|
# Reporter that reports in human readable format
|
|
|
|
class CLI < self
|
2014-08-10 22:09:29 +00:00
|
|
|
include Concord.new(:output, :format)
|
2012-08-29 13:36:29 +02:00
|
|
|
|
2014-08-10 22:09:29 +00:00
|
|
|
# Build reporter
|
|
|
|
#
|
|
|
|
# @param [IO] output
|
|
|
|
#
|
|
|
|
# @return [Reporter::CLI]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def self.build(output)
|
2015-05-02 22:25:36 +00:00
|
|
|
tput = Tput.detect
|
2014-08-10 22:09:29 +00:00
|
|
|
tty = output.respond_to?(:tty?) && output.tty?
|
2015-05-02 22:25:36 +00:00
|
|
|
format = if !Mutant.ci? && tty && tput
|
|
|
|
Format::Framed.new(tty: tty, tput: tput)
|
2014-12-22 01:28:30 +00:00
|
|
|
else
|
|
|
|
Format::Progressive.new(tty: tty)
|
|
|
|
end
|
2014-08-10 22:09:29 +00:00
|
|
|
new(output, format)
|
|
|
|
end
|
2014-07-17 13:59:25 +00:00
|
|
|
|
2014-08-10 22:09:29 +00:00
|
|
|
# Report start
|
2014-07-17 13:59:25 +00:00
|
|
|
#
|
2014-08-10 22:09:29 +00:00
|
|
|
# @param [Env] env
|
2014-07-17 13:59:25 +00:00
|
|
|
#
|
2014-12-01 18:33:47 +00:00
|
|
|
# @return [self]
|
|
|
|
#
|
2014-07-17 13:59:25 +00:00
|
|
|
# @api private
|
2014-08-10 22:09:29 +00:00
|
|
|
def start(env)
|
|
|
|
write(format.start(env))
|
|
|
|
self
|
2014-07-17 13:59:25 +00:00
|
|
|
end
|
|
|
|
|
2014-05-12 13:48:15 +00:00
|
|
|
# Report progress object
|
|
|
|
#
|
2014-12-09 00:10:31 +00:00
|
|
|
# @param [Parallel::Status] status
|
2014-05-12 13:48:15 +00:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
2014-12-09 00:10:31 +00:00
|
|
|
def progress(status)
|
|
|
|
write(format.progress(status))
|
2014-05-12 13:48:15 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2015-07-03 15:21:39 +00:00
|
|
|
# Report delay in seconds
|
2014-12-08 18:13:49 +00:00
|
|
|
#
|
|
|
|
# TODO: Move this to a callback registration
|
|
|
|
#
|
|
|
|
# @return [Float]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def delay
|
|
|
|
format.delay
|
|
|
|
end
|
|
|
|
|
2014-06-30 13:19:47 +00:00
|
|
|
# Report warning
|
|
|
|
#
|
|
|
|
# @param [String] message
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
def warn(message)
|
|
|
|
output.puts(message)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2014-07-17 13:59:25 +00:00
|
|
|
# Report env
|
2013-04-21 02:20:18 +02:00
|
|
|
#
|
2014-07-17 13:59:25 +00:00
|
|
|
# @param [Result::Env] env
|
2013-04-21 02:20:18 +02:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
2014-07-17 13:59:25 +00:00
|
|
|
def report(env)
|
2015-05-03 00:21:30 +00:00
|
|
|
Printer::EnvResult.call(output, env)
|
2013-04-21 02:20:18 +02:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2014-07-17 13:59:25 +00:00
|
|
|
private
|
|
|
|
|
2014-08-10 22:09:29 +00:00
|
|
|
# Write output frame
|
2014-07-17 13:59:25 +00:00
|
|
|
#
|
|
|
|
# @param [String] frame
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
2014-08-10 22:09:29 +00:00
|
|
|
def write(frame)
|
2014-07-17 13:59:25 +00:00
|
|
|
output.write(frame)
|
|
|
|
end
|
|
|
|
|
2013-06-14 20:54:02 +02:00
|
|
|
end # CLI
|
|
|
|
end # Reporter
|
|
|
|
end # Mutant
|