Class: AsgDetailer::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/asg-detailer/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



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
# File 'lib/asg-detailer/cli.rb', line 9

def initialize(args)
  options = {}
  opt_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: asg-detailer [ option ... ]'

    opts.separator ''
    opts.separator 'Specific options:'

    opts.on('-a', '--asg STRING', String, 'The ASG name') do |asg|
      options[:asg] = asg
    end

    opts.on('-j', '--json', 'Output data as JSON') do |json|
      options[:json] = true
    end

    opts.on('-p', '--pretty-json', 'Output data as pretty_generated JSON') do |pretty|
      options[:pretty] = true
    end
  end

  opt_parser.parse!(args)
  if options[:asg].nil?
    puts opt_parser
    exit
  end

  self.run(options)
end

Instance Attribute Details

#confObject

Returns the value of attribute conf.



7
8
9
# File 'lib/asg-detailer/cli.rb', line 7

def conf
  @conf
end

Instance Method Details

#run(options) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/asg-detailer/cli.rb', line 39

def run(options)
  if options[:pretty]
    Detailer.new(options[:asg]).json_pretty
  elsif options[:json]
    puts Detailer.new(options[:asg]).json
  else
    Detailer.new(options[:asg]).print
  end
end