#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'yaml'
require 'ostruct'
require 'cloud'
require 'bosh/cpi'

require 'cloud/vcloud'

cpi_config = YAML.load_file(ARGV.shift)

cloud_config = OpenStruct.new(:logger => Logger.new(STDERR))

Bosh::Clouds::Config.configure(cloud_config)

cpi_log = StringIO.new #TODO: cloud_properties['log_file'] ?

cpi_lambda = lambda do
  unless cpi_config.has_key?('cloud') && cpi_config['cloud'].has_key?('properties')
    raise "Could not find cloud properties in the configuration"
  end

  cloud_properties = cpi_config['cloud']['properties']
  Bosh::Clouds::Vcloud.new(cloud_properties)
end

cli = Bosh::Cpi::Cli.new(cpi_lambda, cpi_log, STDOUT)

cli.run(ARGF.read)
