Class: Estool::Actions::Cat

Inherits:
Object
  • Object
show all
Defined in:
lib/estool/actions/cat.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, options) ⇒ Cat

Returns a new instance of Cat.



8
9
10
11
12
# File 'lib/estool/actions/cat.rb', line 8

def initialize(command,options)
  @cmd = command
  @data = options.except(:host, :port)
  @server = options.slice(:host, :port)
end

Instance Method Details

#cat(action, options, server) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/estool/actions/cat.rb', line 35

def cat(action, options, server)
  client = Estool::Connections.start_conn(server[:host], server[:port])
  Estool::Connections.test_conn(client)
  begin
    puts client.cat.send(action, options)
  rescue ArgumentError => args
    puts "
         #{args}
    Usage: 'estool help #{action}' for more information
    "
    exit 1
  end
end

#format_options(data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/estool/actions/cat.rb', line 14

def format_options(data)
  params = {}
  data.each do |k, v|
    case k
    when :verbose
        params.merge!(v: v)
      when :output
        params.merge!(format: v)
      when :name
        params.merge!(name: v)
      when :node
        params.merge!(node_id: v)
      when :primary
        params.merge!(pri: v)
      else
        params.merge!("#{k}": v)
    end
  end
  return params
end

#runObject



49
50
51
52
# File 'lib/estool/actions/cat.rb', line 49

def run
  params = format_options(@data)
  cat(@cmd, params, @server)
end