Class: ResourceIn::Command

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

Class Method Summary collapse

Class Method Details

.get(opts, argv) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/resource_in/command.rb', line 31

def self.get(opts, argv)
  unless !!Config['ignore-auth'] or Authorization.is_user?
    puts "[Warning] User '#{ENV['USER']}' needs 'User' permission to execute command 'get'"
    return
  end

  machine = Machine.new

  begin
    data = machine.get(argv.first)
    if data != [nil]
      machine.output_detail(data)
    else
      puts "warning: no such resource '#{argv.first}' in this environment."
      exit 1
    end
  rescue InvalidArgument => e
    puts "[warning] #{e.message}"
  end
end

.list(opts, argv) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/resource_in/command.rb', line 8

def self.list(opts, argv)
  unless !!Config['ignore-auth'] or Authorization.is_viewer?
    puts "[Warning] User '#{ENV['USER']}' needs 'Viewer' permission to execute command 'list'"
    return
  end

  resource_kls = case opts[:type]
  when 'all'
    Machine
  when 'machine'
    Machine
  else
    raise 'unknown type is detected'
  end

  resource = resource_kls.new

  begin
    resource.output(resource.filter(argv.first, resource.list))
  rescue InvalidArgument => e
    puts "[warning] #{e.message}"
  end
end