#!/usr/bin/ruby

require_relative "../lib/cobratest"
require "optparse"

options = {
  display: "results",
  path: nil
}

instructions = OptionParser.new do |opts|
  opts.banner = "cobratest [OPTION] [application path]\n\n"
  opts.separator "Test runner employing the structure of Component-based Ruby/Rails apps to optimize what needs to run.\n\n"
  opts.separator "Options are...\n"

  opts.on("-h", "-H", "--help", "Display this help message.") do
    puts opts
    exit
  end

  opts.on("-r", "--results", "DEFAULT Display the directories of the components in need of running tests") do
    options[:display] = "results"
  end

  opts.on("-t", "--test-runner RUNNER", "Choose a test runner") do |runner|
    options[:runner] = runner
  end

  opts.on("-v", "--verbose", "Verbose output of all parts of the calculation") do
    options[:display] = "verbose"
  end

  opts.on("-s", "--since BRANCH", "Specify BRANCH target to calculate against") do |branch|
    options[:since] = branch
  end
end

begin
  instructions.parse!
  if ARGV.size >= 1
    Cbratest::Runner.new(options).run ARGV[0]
  else
    raise OptionParser::MissingArgument.new("Must specify the application path")
  end
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => error
  puts error
  puts instructions
  exit
end