#!/usr/bin/env ruby require 'rubygems' $:.unshift(File.expand_path("../../lib", __FILE__)) require 'earl_report' require 'getoptlong' require 'yaml' OPT_ARGS = [ ["--base", GetoptLong::REQUIRED_ARGUMENT,"Base URI to use when loading test manifest"], ["--bibRef", GetoptLong::REQUIRED_ARGUMENT,"ReSpec BibRef of specification being reported upon"], ["--format", "-f", GetoptLong::REQUIRED_ARGUMENT,"Format of output, one of 'ttl', 'json', or 'html'. May also be a different RDF format"], ["--json", GetoptLong::NO_ARGUMENT, "Input is a JSON-LD formatted result"], ["--manifest", GetoptLong::REQUIRED_ARGUMENT,"Test manifest(s)"], ["--name", GetoptLong::REQUIRED_ARGUMENT,"Name of specification"], ["--output", "-o", GetoptLong::REQUIRED_ARGUMENT,"Output report to file"], ["--query", GetoptLong::REQUIRED_ARGUMENT,"Query, or file containing query for extracting information from Test manifest"], ["--rc", GetoptLong::NO_ARGUMENT, "Write options to run-control file"], ["--template", GetoptLong::OPTIONAL_ARGUMENT,"Specify or return default report template"], ["--verbose", GetoptLong::NO_ARGUMENT, "Detail on execution"], ["--help", "-?", GetoptLong::NO_ARGUMENT, "This message"] ] def usage STDERR.puts %{ earl-report version #{EarlReport::VERSION} Generate EARL report for mutliple test results against a test manifest. See http://gkellogg.github.io/earl-report/ for assumptions on individual reports and test manifests. Options are initialized by reading optional run-control file '.earl' in the local directory, if it exists. Writing with a format other than ttl, json, or html will also write any loaded manifests Usage: #{$0} [options] test-result ... }.gsub(/^ /, '') width = OPT_ARGS.map do |o| l = o.first.length l += o[1].length + 2 if o[1].is_a?(String) l end.max OPT_ARGS.each do |o| s = " %-*s " % [width, (o[1].is_a?(String) ? "#{o[0,2].join(', ')}" : o[0])] s += o.last STDERR.puts s end exit(1) end opts = GetoptLong.new(*OPT_ARGS.map {|o| o[0..-2]}) options = { :format => :html, :io => STDOUT} options.merge!(YAML.load(File.open ".earl")) if File.exist?(".earl") opts.each do |opt, arg| case opt when '--base' then options[:base] = arg when '--bibRef' then options[:bibRef] = arg when '--format' then options[:format] = arg.to_sym when '--manifest' then options[:manifest] = arg.split(',').map(&:strip) when '--query' then options[:query] = arg when '--base' then options[:base] = arg when '--json' then options[:json] = true when '--name' then options[:name] = arg when '--output' then options[:io] = File.open(arg, "w") when '--rc' then options[:rc] = true when '--template' then options[:template] = (File.open(arg, "r") unless arg.empty?) when '--verbose' then options[:verbose] = true when '--help' then usage else options[opt.to_sym] = arg end end # Replace query from a specified file, with the query itself if options.has_key?(:query) && File.exist?(options[:query]) options[:query] = File.read(options[:query]) end # Write run-control file to output if options.has_key?(:rc) io = options.delete(:io) || STDOUT options.delete_if {|k, v| [:rc, :json, :output, :verbose].include?(k)} io.puts options.to_yaml exit 0 end # If requesting template, just return it if options.has_key?(:template) && options[:template].nil? File.open(File.expand_path("../../lib/earl_report/views/earl_report.html.haml", __FILE__)) do |f| options[:io].write(f.read) end elsif ARGV.empty? usage else earl = EarlReport.new(*ARGV, options) earl.generate(options) end