module RHC::OutputHelpers

Public Instance Methods

add_issue(reason, commands_header, *commands) click to toggle source

Issues collector collects a set of recoverable issues and steps to fix them for output at the end of a complex command

# File lib/rhc/output_helpers.rb, line 5
def add_issue(reason, commands_header, *commands)
  @issues ||= []
  issue = {:reason => reason,
           :commands_header => commands_header,
           :commands => commands}
  @issues << issue
end
display_app(app,cartridges = nil,scalable_cart = nil) click to toggle source
# File lib/rhc/output_helpers.rb, line 50
def display_app(app,cartridges = nil,scalable_cart = nil)
  heading = "%s @ %s" % [app.name, app.app_url]
  paragraph do
    header heading do
      display_app_properties(app,:creation_time,:uuid,:gear_profile,:git_url,:ssh_url,:aliases)
      display_included_carts(cartridges) if cartridges
      display_scaling_info(app,scalable_cart) if scalable_cart
    end
  end
end
display_app_properties(app,*properties) click to toggle source
# File lib/rhc/output_helpers.rb, line 61
def display_app_properties(app,*properties)
  say_table          "Application Info",
    get_properties(app,*properties),
    :delete => true
end
display_cart(cart,properties = nil) click to toggle source
# File lib/rhc/output_helpers.rb, line 99
def display_cart(cart,properties = nil)
  @table_displayed = false
  header cart.name do
    display_cart_properties(cart,properties) if properties
    display_cart_scaling_info(cart) if cart.scalable?
    display_no_info("cartridge") unless @table_displayed
  end
end
display_cart_properties(cart,properties) click to toggle source
# File lib/rhc/output_helpers.rb, line 108
def display_cart_properties(cart,properties)
  # We need to actually access the cart because it's not a simple hash
  properties = get_properties(cart,*properties.keys) do |prop|
    cart.property(:cart_data,prop)["value"]
  end

  say_table          "Properties",
    properties
end
display_cart_scaling_info(cart) click to toggle source
# File lib/rhc/output_helpers.rb, line 119
def display_cart_scaling_info(cart)
  say_table          "Scaling Info",
    get_properties(cart,:current_scale,:scales_from,:scales_to)
end
display_domain(domain) click to toggle source

This is a little different because we don't want to recreate the #display_app function

# File lib/rhc/output_helpers.rb, line 38
def display_domain(domain)
  say "No domain exists.  You can use 'rhc domain create' to create a namespace for applications." and return unless domain
  header "Applications in %s" % domain.id do
    domain.applications.each do |a|
      display_app(a,a.cartridges,a.scalable_carts.first)
    end.blank? and say "No applications. You can use 'rhc app create' to create new applications."
  end
end
display_included_carts(carts) click to toggle source
# File lib/rhc/output_helpers.rb, line 68
def display_included_carts(carts)
  properties = Hash[carts.map do |cart|
    [cart.name,cart.connection_info]
  end]

  properties = "None" unless properties.present?

  say_table          "Cartridges",
    properties,
    :preserve_keys => true
end
display_no_info(type) click to toggle source
# File lib/rhc/output_helpers.rb, line 129
def display_no_info(type)
  say_table          nil,
    ["This #{type} has no information to show"]
end
display_scaling_info(app,cart) click to toggle source
# File lib/rhc/output_helpers.rb, line 81
def display_scaling_info(app,cart)
  # Save these values for easier reuse
  values = [:current_scale,:scales_from,:scales_to,:scales_with]
  # Get the scaling properties we care about
  properties = get_properties(cart,*values)
  # Format the string for applications
  properties = "Scaled x%d (minimum: %s, maximum: %s) with %s on %s gears" %
    [properties.values_at(*values), app.gear_profile].flatten

  say_table          "Scaling Info",
    properties
end
format_issues(indent) click to toggle source
# File lib/rhc/output_helpers.rb, line 13
def format_issues(indent)
  return nil unless issues?

  indentation = " " * indent
  reasons = ""
  steps = ""

  @issues.each_with_index do |issue, i|
    reasons << "#{indentation}#{i+1}. #{issue[:reason].strip}\n"
    steps << "#{indentation}#{i+1}. #{issue[:commands_header].strip}\n"
    issue[:commands].each { |cmd| steps << "#{indentation}  $ #{cmd}\n" }
  end

  [reasons, steps]
end
issues?() click to toggle source
# File lib/rhc/output_helpers.rb, line 29
def issues?
  not @issues.nil?
end