Class: FauxhaiGenerator::Config
- Inherits:
-
Object
- Object
- FauxhaiGenerator::Config
- Defined in:
- lib/fauxhai_generator/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#load_config ⇒ Object
the config in config.yml mixed in with the key_name/key_path passed via CLI.
-
#options ⇒ Object
parse the command line options.
-
#readiness_check ⇒ Object
fail if things aren’t in order.
Constructor Details
#initialize ⇒ Config
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
#config ⇒ Object (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_config ⇒ Object
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 = 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 |
#options ⇒ Object
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 # since optparse doesn't have a "required" flag we have to hack one on ARGV << "-h" if ARGV.count < 6 = {} OptionParser.new do |opts| opts. = "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) ["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) ["key_path"] = n end opts.on("-k", "--key_name KEYNAME ", "The name of the keypair to setup AWS instances with. (required)") do |n| ["key_name"] = n end opts.on("-h", "--help", "Display fauxhai_generator options") do puts opts exit end end.parse! end |
#readiness_check ⇒ Object
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 |