#!/usr/bin/env ruby require 'quarry' require 'getoptlong' module Quarry # = Quarry Commandline Utility # class Command def self.execute new.execute end attr :reporter def initialize @reporter = nil end def opts @opts ||= GetoptLong.new( [ '--version', GetoptLong::NO_ARGUMENT ], [ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--debug', '-d', GetoptLong::NO_ARGUMENT ], [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], [ '--summary', '-s', GetoptLong::NO_ARGUMENT ], [ '--loadpath', '-I', GetoptLong::REQUIRED_ARGUMENT ] ) end # def parse_options opts.each do |opt, arg| case opt when '--help' puts HELP exit when '--debug' $DEBUG = true when '--verbose' @reporter = :verbose when '--summary' @reporter = :summary when '--loadpath' arg.split(/[:;]/).each{|dir| $LOAD_PATH.unshift(dir)} end end end # def load_rc if rcfile = Dir['.config/quarry{,rc}{,.rb}'].first load(rcfile) end end # TODO: Should there be any file filter? def specs specs = [] spec_files.each do |file| case File.extname(file) when '.rb' #load(file) else specs << Quarry::Markup.new(file) end end specs end # def spec_files ARGV.collect do |file| if File.directory?(file) Dir[File.join(file, '**', '*')] else file end end.flatten.uniq end # def output case reporter when :verbose Quarry::Reporter::Verbatim.new when :summary Quarry::Reporter::Summary.new else nil end end def runner Quarry::Runner.new(specs, output) end # def execute parse_options load_rc runner.check end HELP = <<-END quarry [--options] [specs...] Options: -v --verbose -s --summary -h --help --version END end end Quarry::Command.execute