#!/usr/bin/env ruby

# parse raw -v but not verbose
if ARGV == ["-v"] || ARGV == ["--version"]
  puts Maxitest::VERSION
  exit 0
end

# parse raw -h
if ARGV == ["-h"] || ARGV == ["--help"]
  puts <<~EOF
    test given file, folder or file:line
    Usage: mtest foo_test.rb

    -v to run without bracktrace cleaner
    --changed to run all all tests in current `git diff` or `git show`
  EOF
  exit 0
end

# send rest to testrbl to get --changed support, but do not guess at lines but just convert number to -l
# so minitest-line picks it up
require 'optparse'

$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'maxitest/vendor/testrbl'

class << Maxitest::Testrbl
  def line_pattern_option(file, line)
    [file, "-l", line]
  end
end

Maxitest::Testrbl.run_from_cli(ARGV)
