Method: Consolr::Console#initialize
- Defined in:
- lib/consolr.rb
#initialize ⇒ Console
Returns a new instance of Console.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/consolr.rb', line 14 def initialize potential_config_paths = [ENV['CONSOLR_CONFIG'], '~/.consolr.yml', '~/.consolr.yaml', '/etc/consolr.yml', '/etc/consolr.yaml', '/var/db/consolr.yml', '/var/db/consolr.yaml'] config_file = potential_config_paths.compact.find do |conf| begin = File.(conf, __FILE__) File.readable?() and File.size() > 0 rescue ArgumentError # if $HOME is not set, or if `~` cannot be expanded, `expand_path` will throw and ArgumentError # in that case, just go to the next potential config file - this one obviously will not work false end end @config_params = begin YAML.load(File.open(File.(config_file, __FILE__))) rescue TypeError => e puts "-------" puts "Failed to load Configuration File ... " puts "Looks like a configuration file doesn't exist." puts "Please look at README.md on creating a configuration file" puts "-------" exit 1 rescue ArgumentError => e puts "------" puts "Failed to load Configuration File ... " puts "Looks like the configuration file is not correctly formatted" puts "Please check if your file conforms to YAML spec" puts "------" exit 1 end # # Will be ignored for dangerous actions, no matter what, even with --force begin @dangerous_assets = @config_params['dangerous_assets'] rescue Exception => e puts e puts "-------" puts "Dangerous Assets -- #{dangrous}" puts "Please make sure dangerous_assets exists and is valid." puts "Supply them in a comma separated list." end # Dangerous actions wont be run in these status, override with --force begin @dangerous_status = @config_params['dangerous_status'] rescue Exception => e puts e puts "-------" puts "Dangerous Status -- #{@dangeous_status}" puts "Please specify the statuses which are dangerorous, during which dangerous shouldn't be run." puts "-------" exit 1 end @dangerous_actions = [:off, :reboot] # Must match the symbol in options{} end |