Module: Brightbox

Extended by:
GLI
Includes:
Logging
Defined in:
lib/bbcloud/api.rb,
lib/bbcloud/types.rb,
lib/bbcloud/users.rb,
lib/bbcloud/zones.rb,
lib/bbcloud/config.rb,
lib/bbcloud/images.rb,
lib/bbcloud/tables.rb,
lib/bbcloud/logging.rb,
lib/bbcloud/servers.rb,
lib/bbcloud/version.rb,
lib/bbcloud/accounts.rb,
lib/bbcloud/cloud_ips.rb,
lib/bbcloud/error_parser.rb,
lib/bbcloud/load_balancers.rb,
lib/bbcloud/gli_global_hooks.rb,
lib/bbcloud/command_generator.rb,
lib/bbcloud/commands/lbs-list.rb,
lib/bbcloud/commands/lbs-show.rb,
lib/bbcloud/commands/lbs-create.rb,
lib/bbcloud/commands/lbs-update.rb,
lib/bbcloud/commands/types-list.rb,
lib/bbcloud/commands/types-show.rb,
lib/bbcloud/commands/users-list.rb,
lib/bbcloud/commands/users-show.rb,
lib/bbcloud/commands/zones-list.rb,
lib/bbcloud/commands/images-list.rb,
lib/bbcloud/commands/images-show.rb,
lib/bbcloud/commands/lbs-destroy.rb,
lib/bbcloud/commands/cloudips-map.rb,
lib/bbcloud/commands/servers-list.rb,
lib/bbcloud/commands/servers-show.rb,
lib/bbcloud/commands/servers-stop.rb,
lib/bbcloud/commands/users-update.rb,
lib/bbcloud/commands/accounts-list.rb,
lib/bbcloud/commands/accounts-show.rb,
lib/bbcloud/commands/cloudips-list.rb,
lib/bbcloud/commands/cloudips-show.rb,
lib/bbcloud/commands/lbs-add-nodes.rb,
lib/bbcloud/commands/servers-start.rb,
lib/bbcloud/commands/cloudips-unmap.rb,
lib/bbcloud/commands/images-destroy.rb,
lib/bbcloud/commands/servers-create.rb,
lib/bbcloud/commands/cloudips-create.rb,
lib/bbcloud/commands/images-register.rb,
lib/bbcloud/commands/servers-destroy.rb,
lib/bbcloud/commands/cloudips-destroy.rb,
lib/bbcloud/commands/lbs-remove-nodes.rb,
lib/bbcloud/commands/servers-shutdown.rb,
lib/bbcloud/commands/servers-snapshot.rb,
lib/bbcloud/commands/config-client-add.rb,
lib/bbcloud/commands/config-client-list.rb,
lib/bbcloud/commands/config-client-remove.rb,
lib/bbcloud/commands/config-client-default.rb,
lib/bbcloud/commands/servers-activate-cloud.rb,
lib/bbcloud/commands/accounts-reset-ftp-password.rb

Defined Under Namespace

Modules: Logging Classes: Account, Api, BBConfig, BBConfigError, CloudIP, CommandGenerator, ErrorParser, Image, LoadBalancer, Server, ShowTable, SimpleTable, Type, User, Zone

Constant Summary collapse

VERSION =
"0.13.0"

Class Method Summary collapse

Methods included from GLI

arg_name, clear_nexts, command, commands, config_file, convert_to_openstruct?, copy_options_to_aliased_versions, default_value, desc, error_device=, error_message, exit_now!, find_command, find_non_flag_index, flag, flag_switch_index, flags, long_desc, on_error, parse_config, parse_options, parse_options_helper, post, pre, proceed?, program_desc, program_name, regular_error_handling?, reset, run, skips_post, skips_pre, switch, switches, use_openstruct, verify_unused, version

Methods included from GLI::CopyOptionsToAliases

#copy_options_to_aliases

Methods included from Logging

included

Class Method Details

.render_table(rows, options = {}) ⇒ Object

Print nice ascii tables (or tab separated lists, depending on mode) Has lots of magic.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bbcloud/tables.rb', line 60

def render_table(rows, options = {})
  options = { :description => false }.merge options
  # Figure out the fields from the :model option
  if options[:model] and options[:fields].nil?
    options[:fields] = options[:model].default_field_order
  end
  # Figure out the fields from the first row
  if options[:fields].nil? and rows.first.class.respond_to?(:default_field_order)
    options[:fields] = rows.first.class.default_field_order
  end
  # Call to_row on all the rows
  rows = rows.collect do |row|
    row.respond_to?(:to_row) ? row.to_row : row
  end
  # Call render_cell on all the cells
  rows.each do |row|
    row.keys.each do |k|
      row[k] = row[k].render_cell if row[k].respond_to? :render_cell
    end
  end
  if options[:s]
    # Simple output
    rows.each do |row|
      if options[:vertical]
        data options[:fields].collect { |k| [k, row[k]].join("\t") }.join("\n")
      else
        data options[:fields].collect { |k| row[k] }.join("\t")
      end
    end
  else
    # "graphical" table
    if options[:vertical]
      data ShowTable.render(rows, options)
    else
      data SimpleTable.render(rows, options)
    end
  end
end