lib = File.dirname(__FILE__) + '/../lib'
iis_lib = 'rack/deploy/iis'
if File.directory? lib
  require File.join(lib, iis_lib)
else
  require 'rubygems'
  gem 'ironruby-rack'
  require iis_lib
end

def parse_arguments(argv)
  config = argv[0] != 'remove' ? [:deploy, 0, 1] : [:remove, 1, 2]
  app_name = String.new(argv[config[1]]) rescue raise("Application name required as first command-line arg")
  app_path = if config[0] == :deploy
    _path = String.new(argv[config[2]]) rescue raise("Application path required as second command-line arg")
    File.expand_path(_path, '.').gsub('/', '\\')
  else
    nil
  end
  return {:mode => config.first, :app_name => app_name, :app_path => app_path}
rescue => e
  puts <<EOS

Failed with exception: #{e}\n  #{e.backtrace.join("\n  ")}

Please make sure following:
  1. IIS is installed
  2. On Vista, IIS6 Management Compatibility component is installed.
  3. On Vista, this tool run as Administrator
EOS
  exit -1
end

opts = parse_arguments(ARGV)

Rack::Deploy::IIS.send opts[:mode], opts
