#!/usr/bin/env ruby if RUBY_VERSION < '1.8.7' abort "error: XCPretty requires Ruby 1.8.7 or higher." end if $0 == __FILE__ $:.unshift File.expand_path('../../lib', __FILE__) end require 'xcpretty' require 'optparse' def class_from_path(path) source = File.read(path) klass = eval(source, nil, path) raise unless klass.is_a?(Class) klass end def load_custom_formatter(path) begin $:.unshift File.dirname(path) class_from_path(path) rescue SyntaxError => e $stderr.puts "[!] Expected formatter source file to return a class. #{e}" exit 1 end end report_formats = { "junit" => XCPretty::JUnit } constructor = { :unicode => true, :colorize => false, :formatter => XCPretty::Simple } reporter_classes = [] OptionParser.new do |opts| opts.banner = "Usage: xcodebuild [options] | xcpretty" opts.on('-t', '--test', 'Use RSpec style output') do constructor[:formatter] = XCPretty::RSpec end opts.on('-s', '--simple', 'Use simple output (default)') do constructor[:formatter] = XCPretty::Simple end opts.on('-f', '--formatter PATH', 'Use formatter returned from evaluating the specified Ruby file') do |path| constructor[:formatter] = load_custom_formatter(path) end opts.on('-c', '--color', 'Use colorized output') do constructor[:colorize] = true end opts.on('--no-utf', 'Disable unicode characters in output') do constructor[:unicode] = false end opts.on("-r", "--report FORMAT", "Run FORMAT reporter", " Choices: #{report_formats.keys.join(', ')}") do |format| reporter_classes << report_formats[format] end opts.on_tail('-h', '--help', 'Show this message') { puts opts; exit } opts.on_tail("-v", "--version", "Show version") { puts XCPretty::VERSION; exit } opts.parse! if STDIN.tty? $stderr.puts opts.help exit 1 end end printer = XCPretty::Printer.new(constructor) reporters = reporter_classes.compact.map(&:new) ARGF.each_line do |line| XCPretty::ExitStatus.handle(line) printer.pretty_print(line) reporters.each { |r| r.handle(line) } end reporters.each(&:finish) exit(XCPretty::ExitStatus.code)