Module: Priam::Core::Common

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

Class Method Summary collapse

Class Method Details

.parse_opts(argv) ⇒ Object



3
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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/priam/core/common.rb', line 3

def self.parse_opts(argv)
  host = 'localhost'
  port = 9160
  raise_exception_flag = false
  
  unit_size = 10000
  retry_max_count = 5
  weight_second = 1

  check_exist_flag = false
  output_keys_flag = false
  
  replication_factor = 1
  
  json_flag = false
  verbose_flag = false
  with_key_flag = false
  
  next_argv = []
  
  while 0 < argv.size do
    val = argv.shift
    case val
    when '-h'
      host = argv.shift
    when '-p'
      port = argv.shift.to_i
    when '--keyspace'
      keyspace = argv.shift
    when '--column-family'
      column_family = argv.shift
    when '--super-column'
      super_column = argv.shift
    when '--name'
      name = argv.shift
    when '--raise-exception'
      raise_exception_flag = true
    when '--unit-size'
      unit_size = argv.shift.to_i
    when '--value-column'
      value_column = argv.shift
    when '--weight'
      weight_second = argv.shift.to_f / 1000
    when '--retry'
      retry_max_count = argv.shift.to_i
    when '--count-log'
      count_log_path = argv.shift
    when '--check-exist'
      check_exist_flag = true
    when '--output-keys'
      output_keys_flag = true
    when '--replication-factor'
      replication_factor = argv.shift.to_i
    when '--json'
      json_flag = true
    when '--verbose'
      verbose_flag = true
    when '--with-key'
      with_key_flag = true
    else 
      next_argv.push val
    end
  end
  argv.push(*next_argv)
  
  if verbose_flag then
    Priam.logger.level = Logger::INFO
  else
    Priam.logger.level = Logger::WARN
  end
  
  return {
    :host=>host,
    :port=>port,
    :keyspace=>keyspace,
    :column_family=>column_family,
    :super_column=>super_column,
    :name=>name || value_column,
    :raise_exception_flag=>raise_exception_flag,
    :unit_size=>unit_size,
    :value_column=>value_column || name,
    :weight_second=>weight_second,
    :retry_max_count=>retry_max_count,
    :count_log_path=>count_log_path,
    :check_exist_flag=>check_exist_flag,
    :output_keys_flag=>output_keys_flag,
    :replication_factor=>replication_factor,
    :json_flag=>json_flag,
    :verbose_flag=>verbose_flag,
    :with_key_flag=>with_key_flag
  }
end