#!/usr/bin/env ruby require 'rubygems' require 'optparse' require 'clouddns' options = { :fog => {}, :force => false } OptionParser.new do |opts| opts.banner = "Usage: #{$0} [OPTIONS] [ACTION] FILES" opts.on('-p', '--provider provider', "Override DNS provider (AWS, Zerigo, etc)") do |provider| options[:fog][:provider] = provider end opts.on('-f', '--force', 'Assume yes to all questions') do options[:force] = true end opts.on('-v', '--version') do puts "clouddns v#{Clouddns::VERSION}" exit(0) end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end.parse! action = ARGV.slice!(0) files = ARGV raise "No action specified" unless action raise "No files specified" if files.empty? action = Clouddns::Actions.by_name(action) zones = files.map do |file| dsl = Clouddns::DSL.parse_file(file) dsloptions = {:fog => dsl.fog_options}.merge(options) do |key, oldval, newval| oldval.merge(newval) end dsl.zones.each do |zone| action.run(zone, dsloptions) end end