Class: FauxhaiGenerator::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/fauxhai_generator/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



6
7
8
9
# File 'lib/fauxhai_generator/config.rb', line 6

def initialize
  readiness_check
  @config = load_config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/fauxhai_generator/config.rb', line 11

def config
  @config
end

Instance Method Details

#load_configObject

the config in config.yml mixed in with the key_name/key_path passed via CLI



50
51
52
53
54
55
56
# File 'lib/fauxhai_generator/config.rb', line 50

def load_config
  opts = options
  yaml = YAML.safe_load(File.open(opts["config_file"]))
  yaml["aws"]["key_name"] = opts["key_name"]
  yaml["aws"]["key_path"] = opts["key_path"]
  yaml
end

#optionsObject

parse the command line options



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fauxhai_generator/config.rb', line 14

def options
  # since optparse doesn't have a "required" flag we have to hack one on
  ARGV << "-h" if ARGV.count < 6

  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: fauxhai_generator [options]"

    opts.on("-c", "--config FILE_PATH ", "fauxhai_generator config.yml file path. (required)") do |n|
      raise "The passed config file at #{n} does not exist!" unless File.exist?(n)
      options["config_file"] = n
    end

    opts.on("-f", "--key-file FILE_PATH ", "The path to the key used to login to AWS instances. (required)") do |n|
      raise "The passed key file at #{n} does not exist!" unless File.exist?(n)
      options["key_path"] = n
    end

    opts.on("-k", "--key_name KEYNAME ", "The name of the keypair to setup AWS instances with. (required)") do |n|
      options["key_name"] = n
    end

    opts.on("-h", "--help", "Display fauxhai_generator options") do
      puts opts
      exit
    end
  end.parse!
  options
end

#readiness_checkObject

fail if things aren’t in order



45
46
47
# File 'lib/fauxhai_generator/config.rb', line 45

def readiness_check
  raise "You must run fauxhai_generator from the root of the fauxhai repository!" unless Dir.exist?("lib/fauxhai/platforms")
end