Class: EbsSnapper::CLI
- Inherits:
-
Object
- Object
- EbsSnapper::CLI
- Defined in:
- lib/ebs_snapper/cli.rb
Class Method Summary collapse
- .configure_logger(opts) ⇒ Object
- .load_config(opts, filename) ⇒ Object
- .parse(args) ⇒ Object
- .run ⇒ Object
- .symbolize_keys(hash) ⇒ Object
Class Method Details
.configure_logger(opts) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ebs_snapper/cli.rb', line 36 def self.configure_logger(opts) if opts[:log_to] @logger = ::Logger.new(opts[:log_to]) end @logger ||= ::Logger.new(STDOUT) @logger.level = opts[:verbose] ? Logger::DEBUG : Logger::INFO opts[:aws][:logger] = @logger if opts[:aws] opts end |
.load_config(opts, filename) ⇒ Object
30 31 32 33 34 |
# File 'lib/ebs_snapper/cli.rb', line 30 def self.load_config(opts, filename) config = symbolize_keys(YAML.load_file(filename)) # merge the new file config & update the logger config configure_logger(opts.merge!(config)) end |
.parse(args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ebs_snapper/cli.rb', line 49 def self.parse(args) = {} [:aws] = {} [:ultradns] = {} [:log_to] = nil [:verbose] = false [:out] = '' [:config] = nil opts = OptionParser.new do |opts| opts. = "Usage: ebs_snapper [options]" opts.separator "" opts.separator "Specific options:" opts.on("-c", "--config config.yaml", "Configuration for the updater") do |config| [:config] = config end opts.separator "" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| [:verbose] = v end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("--version", "Show version") do puts EbsSnapper::VERSION exit end end opts.parse!(args) # load the config load_config(, [:config]) end |
.run ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ebs_snapper/cli.rb', line 22 def self.run opts = parse(ARGV) ebs = EbsSnapper::Ebs.new(opts[:aws]) ebs.snapshot_and_purge rescue => e @logger.error "Exception: #{e}\n" + e.backtrace().join("\n") end |
.symbolize_keys(hash) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ebs_snapper/cli.rb', line 91 def self.symbolize_keys(hash) unless hash.nil? hash.replace( hash.each_key.inject({}) do |h, k| v = hash.delete(k) key = k.to_sym rescue k if v.is_a? (Hash) h[key] = symbolize_keys(v) else h[key] = v end h end ) end hash end |