Class: Scaltainer::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/scaltainer/command.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
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/scaltainer/command.rb', line 6

def self.parse(args)
  configfile, statefile, wait = 'scaltainer.yml', nil, 0
  OptionParser.new do |opts|
    opts.banner = "Usage: scaltainer [options]"
    opts.on("-f", "--conf-file FILE", "Specify configuration file (default: scaltainer.yml)") do |file|
      configfile = file
    end
    opts.on("--state-file FILE", "Specify state file (default: <conf-file>.state)") do |file|
      statefile = file
    end
    opts.on("-w", "--wait SECONDS", "Specify wait time between repeated calls, 0 for no repetition (default: 0)") do |w|
      wait = w.to_i
    end
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      puts "\nEnvironment variables: \n"
      puts "- DOCKER_URL: defaults to local socket"
      puts "- HIREFIRE_TOKEN"
      puts "- NEW_RELIC_API_KEY"
      puts "- RESPONSE_TIME_WINDOW: defaults to 5"
      puts "- LOG_LEVEL: defaults to INFO"
      puts "- DOCKER_SECRETS_PATH_GLOB: path glob containing env files to load"
      exit
    end     
  end.parse!

  statefile = "#{configfile}.state" unless statefile

  raise ConfigurationError.new("File not found: #{configfile}") unless File.exists?(configfile)

  load_env

  logger = Logger.new(STDOUT)
  logger.level = %w(debug info warn error fatal unknown).find_index((ENV['LOG_LEVEL'] || '').downcase) || 1

  return configfile, statefile, logger, wait
end