Module: Cawcaw::Core::Common

Defined in:
lib/cawcaw/core/common.rb

Class Method Summary collapse

Class Method Details

.parse_opts(argv) ⇒ Object



4
5
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
43
44
45
46
# File 'lib/cawcaw/core/common.rb', line 4

def self.parse_opts(argv)
  ret = {}
  
  ret[:hadoop_working_directory] = "/user/#{ENV["USER"]}"
  ret[:hadoop_command] = "hadoop"
  
  ret[:stdin_flag] = false
  ret[:verbose_flag] = false
  
  next_argv = []
  
  while 0 < argv.size do
    val = argv.shift
    if val[0..1] == "--"
      label = val[2..-1].gsub(/-/,"_").to_sym
    else
      label = nil
    end
    case label
    when :graph_title, :graph_args, :graph_vlabel, :graph_category, :graph_info, \
         :hadoop_command, :adapter, :host, :database, :username, :password, :encoding
      ret[label] = argv.shift
    when :label_warning, :label_critical, :port
      ret[label] = ret[label].to_i
    when :stdin, :verbose, :stats
      ret["#{label}_flag".to_sym] = true
    when :hadoop_wdir
      hadoop_working_directory = argv.shift
      ret[:hadoop_working_directory] = hadoop_working_directory.gsub(/\/$/, "")
    else
      next_argv.push val
    end
  end
  argv.push(*next_argv)
  
  if ret[:verbose_flag] then
    Cawcaw.logger.level = Logger::INFO
  else
    Cawcaw.logger.level = Logger::WARN
  end
  
  return ret
end