#!/usr/bin/env ruby

require 'ops'

def exit_failure( reason="", code=1 )
  puts reason; exit
end

bootstrap_files = [
  File.join( 'tasks', 'init.rb' ) ]

Dir.chdir Ops::pwd_dir do

  unless Ops::pwd_dir == Dir.pwd
    puts "Executing from ( #{ Ops::pwd_dir } )".warning
  end

  Rake.application.init( File.basename( $0 ) )

  begin
    bootstrap_files.each do | f |
      File.join Ops::root_dir, f
      require f
    end
  rescue => e
    puts e
  end

  bootstrap_files.each do | f |
    f = File.join Ops::pwd_dir, f
    require f if File.exists? f
  end

  begin
    Rake.application.top_level
  rescue => e
    puts "Failed to call task: #{ e.message }"
  end
end

exit
