#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')

if(ENV['SIMPLECOV'] && RUBY_VERSION =~ /1\.9/)
  require 'simplecov'
  SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
  SimpleCov.start
end

require 'cucumber/rspec/disable_option_parser'
require 'cucumber/cli/main'
begin
  # The dup is to keep ARGV intact, so that tools like ruby-debug can respawn.
  failure = Cucumber::Cli::Main.execute(ARGV.dup)
  Kernel.exit(1) if failure
rescue SystemExit => e
  Kernel.exit(e.status)
rescue Exception => e
  STDERR.puts("#{e.message} (#{e.class})")
  STDERR.puts(e.backtrace.join("\n"))
  Kernel.exit(1)
end