Method: Collins::CLI::Formatter#format_assets

Defined in:
lib/collins/cli/formatter.rb

#format_assets(assets, opts = {}) ⇒ Object



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
# File 'lib/collins/cli/formatter.rb', line 47

def format_assets(assets, opts = {})
  opts = FORMATTING_DEFAULTS.merge(opts)
  if assets.length > 0
    case opts[:format]
    when :table
      # if the user passed :column_override, respect that absolutely. otherwise, the columns to display
      # should be opts[:columns] + any extra attributes queried for. this way ```cf -c hostname -a is_vm:true```
      # wont return 2 columns; only the one you asked for
      columns = if opts[:column_override].empty?
                  opts[:columns].concat(search_attrs.keys).compact.uniq
                else
                  opts[:column_override]
                end
      display_as_table(assets,columns,opts[:separator],opts[:show_header])
    when :link
      display_as_link assets, collins
    when :json,:yaml
      display_as_robot_talk(assets,opts[:format])
    else
      raise "I don't know how to display assets in #{opts[:format]} format!"
    end
  else
    raise "No assets found"
  end
end