lib/awstool/settings.rb in awstool-0.0.2 vs lib/awstool/settings.rb in awstool-0.1.0

- old
+ new

@@ -1,17 +1,21 @@ require 'optparse' require 'psych' class Awstool::Settings @options = {} + @option_files = [] attr_reader :options def self.get_options set_default get_rc get_flags + @option_files.each do |f| + @options.merge!(f) + end @options end private @@ -39,31 +43,45 @@ end opts.on('--debug', 'Prints some extra output helpful for debugging') do @options['debug'] = true end - end.parse! - [ 'hostname' ].each do |v| - if ARGV.empty? - puts "#{v} string is required." - exit 1 - else - @options[v] = ARGV.shift + opts.on('-s', '--subnet-id-index INDEX', 'Select a subnet-id from you subnet-ids array.') do |index| + @options['subnet-id-index'] = index.to_i end + + opts.on( + '-o', + '--options-file FILE1,FILE2', + Array, + 'List option files that will merge and override settings in .awstool.yaml. Last entry takes precedence.' ) do |of| + of.each do |f| + @option_files << Psych.load_file(File.expand_path(f)) + end + end + + end.parse! + + if ARGV.empty? + puts "hostname string is required." + exit 1 + else + @options['hostnames'] = ARGV end - @options['tags']['Name'] = @options['hostname'] end def self.get_rc awsconf = "#{ENV['HOME']}/.awstool.yaml" if File.exist?(awsconf) @options.merge!(Psych.load_file(awsconf)) end + @options['subnet-id-index'] = rand(@options['subnet-ids'].length - 1 ) end def self.set_default @options['userdata'] = File.expand_path('../userdata/default.erb') @options['facts'] = {} @options['tags']= {} + @options['hostnames'] = [] end end