Class: Heroku::Scalr::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku/scalr/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/heroku/scalr/cli.rb', line 12

def initialize(argv)
  super()
  @config_path = "./config.rb"
  @options     = { log_level: ::Logger::INFO }
  parser.parse!(argv)

  unless File.file?(@config_path)
    puts parser
    exit
  end
end

Class Method Details

.run!(argv = ARGV) ⇒ Object



8
9
10
# File 'lib/heroku/scalr/cli.rb', line 8

def self.run!(argv = ARGV)
  new(argv).run!
end

Instance Method Details

#parserObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/heroku/scalr/cli.rb', line 30

def parser
  @parser ||= OptionParser.new do |o|
    o.banner = "Usage: heroku-scalr [options]"
    o.separator ""

    o.on("-C", "--config PATH", "Configuration file path. Default: ./config.rb") do |path|
      @config_path = path
    end

    o.on("-l", "--log PATH", "Custom log file path. Default: STDOUT") do |path|
      @options.update log_file: path
    end

    o.on("-v", "--verbose", "Enable verbose logging.") do
      @options.update log_level: ::Logger::DEBUG
    end

    o.separator ""
    o.on_tail("-h", "--help", "Show this message") do
      puts o
      exit
    end
  end
end

#run!Object



24
25
26
27
28
# File 'lib/heroku/scalr/cli.rb', line 24

def run!
  require 'heroku/scalr'
  Heroku::Scalr.configure(@options)
  Heroku::Scalr.run!(@config_path)
end