Class: AwsUtils::Ec2ListMachines

Inherits:
Object
  • Object
show all
Defined in:
lib/awsutils/ec2listmachines.rb

Instance Method Summary collapse

Instance Method Details

#runObject



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

def run
  servers_sorted = formatted_servers.sort_by { |server| server.fetch(opts[:sort].to_sym, '') }

  # Clear all formatting
  printf "\033[0m"

  items = bold_header + servers_sorted.map do |server|
    columns.keys.map do |col|
      # Set an empty string here so that CSV ends up with the right number of cols even when
      # a field is unset
      server[col] || ''
    end
  end.flatten

  if opts[:csv]
    hl = HighLine::List.new items, cols: columns.count
    hl.row_join_string = ','
    puts hl.to_s
  else
    puts HighLine.new.list items, :uneven_columns_across, columns.count
  end
end