Module: RHC::OutputHelpers
- Included in:
- Helpers
- Defined in:
- lib/rhc/output_helpers.rb
Instance Method Summary collapse
- #default_display_env_var(env_var_name, env_var_value = nil) ⇒ Object
-
#display_app(app, cartridges = nil, properties = nil) ⇒ Object
————————— Application information —————————.
- #display_app_configurations(rest_app) ⇒ Object
- #display_authorization(auth, default = nil) ⇒ Object
-
#display_cart(cart, *properties) ⇒ Object
————————— Cartridge information —————————.
- #display_cart_storage_info(cart, title = "Storage Info") ⇒ Object
- #display_cart_storage_list(carts) ⇒ Object
- #display_deployment(item, highlight_active = true) ⇒ Object
- #display_deployment_list(deployment_activations, highlight_active = true) ⇒ Object
- #display_domain(domain, applications = nil, ids = false) ⇒ Object
- #display_env_var_list(env_vars, opts = {}) ⇒ Object
- #display_key(key, *properties) ⇒ Object
- #format_cart_gears(cart) ⇒ Object
- #format_cart_header(cart) ⇒ Object
- #format_gear_info(info) ⇒ Object
- #format_key_header(key) ⇒ Object
- #format_scaling_info(scaling) ⇒ Object
- #format_usage_message(cart) ⇒ Object
Instance Method Details
#default_display_env_var(env_var_name, env_var_value = nil) ⇒ Object
143 144 145 |
# File 'lib/rhc/output_helpers.rb', line 143 def default_display_env_var(env_var_name, env_var_value=nil) info "#{env_var_name}#{env_var_value.nil? ? '' : '=' + env_var_value}" end |
#display_app(app, cartridges = nil, properties = nil) ⇒ Object
Application information
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rhc/output_helpers.rb', line 29 def display_app(app, cartridges=nil, properties=nil) paragraph do header [app.name, "@ #{app.app_url}", "(uuid: #{app.uuid})"] do section(:bottom => 1) do say format_table \ nil, get_properties(app, properties || [:domain, :creation_time, :gear_info, :git_url, :initial_git_url, :ssh_string, :auto_deploy, :aliases]), :delete => true end cartridges.each{ |c| section(:bottom => 1){ display_cart(c) } } if cartridges end end end |
#display_app_configurations(rest_app) ⇒ Object
51 52 53 |
# File 'lib/rhc/output_helpers.rb', line 51 def display_app_configurations(rest_app) display_app(rest_app, nil, [:auto_deploy, :keep_deployments, :deployment_type, :deployment_branch]) end |
#display_authorization(auth, default = nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rhc/output_helpers.rb', line 111 def (auth, default=nil) say format_table( auth.note || "<no description>", get_properties(auth, :token, :scopes, :creation_time, :expires_in_seconds), { :delete => true, :color => (:green if auth.token == default), } ) end |
#display_cart(cart, *properties) ⇒ Object
Cartridge information
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rhc/output_helpers.rb', line 86 def display_cart(cart, *properties) say format_table \ format_cart_header(cart), get_properties(cart, *properties). concat([[:downloaded_cartridge_url, cart.url]]). concat([[cart.scalable? ? :scaling : :gears, format_cart_gears(cart)]]). concat(cart.properties.map{ |p| ["#{table_heading(p['name'])}:", p['value']] }.sort{ |a,b| a[0] <=> b[0] }). concat(cart.environment_variables.present? ? [[:environment_variables, cart.environment_variables.map{|item| "#{item[:name]}=#{item[:value]}" }.sort.join(', ')]] : []), :delete => true say (cart) if cart.usage_rate? end |
#display_cart_storage_info(cart, title = "Storage Info") ⇒ Object
129 130 131 132 133 |
# File 'lib/rhc/output_helpers.rb', line 129 def display_cart_storage_info(cart, title="Storage Info") say format_table \ title, get_properties(cart,:base_gear_storage,:additional_gear_storage) end |
#display_cart_storage_list(carts) ⇒ Object
135 136 137 |
# File 'lib/rhc/output_helpers.rb', line 135 def display_cart_storage_list(carts) carts.each{ |cart| paragraph{ display_cart_storage_info(cart, cart.display_name) } } end |
#display_deployment(item, highlight_active = true) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/rhc/output_helpers.rb', line 159 def display_deployment(item, highlight_active=true) deployment = item[:deployment] active = item[:active] paragraph do say format_table( "Deployment ID #{deployment.id} #{active ? '(active)' : '(inactive)'}", get_properties(deployment, :ref, :sha1, :created_at, :artifact_url, :hot_deploy, :force_clean_build, :activations), { :delete => true, :color => (:green if active && highlight_active) } ) end end |
#display_deployment_list(deployment_activations, highlight_active = true) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/rhc/output_helpers.rb', line 174 def display_deployment_list(deployment_activations, highlight_active=true) if deployment_activations.present? paragraph do deployment_activations.each do |item| activation = item[:activation] deployment = item[:deployment] rollback = item[:rollback] rollback_to = item[:rollback_to] rolled_back = item[:rolled_back] active = item[:active] say color( date(activation.created_at.to_s) + ', deployment ' + deployment.id + (rollback ? " (rollback to #{date(rollback_to.to_s)}#{rolled_back ? ', rolled back' : ''})" : rolled_back ? ' (rolled back)' : ''), active ? :green : rolled_back ? :yellow : nil) end end end end |
#display_domain(domain, applications = nil, ids = false) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rhc/output_helpers.rb', line 4 def display_domain(domain, applications=nil, ids=false) paragraph do header ["Domain #{domain.name}", ("(owned by #{domain.owner})" if domain.owner.present?)] do section(:bottom => 1) do say format_table \ nil, get_properties( domain, :creation_time, (:id if ids), (:allowed_gear_sizes unless domain.allowed_gear_sizes.nil?), :compact_members ), :delete => true end applications.each do |a| display_app(a,a.cartridges) end if applications.present? end end end |
#display_env_var_list(env_vars, opts = {}) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rhc/output_helpers.rb', line 147 def display_env_var_list(env_vars, opts={}) if env_vars.present? if opts[:table] say table(env_vars.collect{ |item| [item.name, opts[:quotes] ? "\"#{item.value}\"" : item.value] }, :header => ['Name', 'Value']) else env_vars.sort.each do |env_var| default_display_env_var(env_var.name, opts[:quotes] ? "\"#{env_var.value}\"" : env_var.value) end end end end |
#display_key(key, *properties) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rhc/output_helpers.rb', line 99 def display_key(key, *properties) properties = [:fingerprint, :principal, :visible_to_ssh?] if properties.empty? say format_table( properties.include?(:name) ? nil : format_key_header(key), get_properties(key, *properties), { :delete => true, :color => (:green if properties.include?(:visible_to_ssh?) && key.visible_to_ssh?), } ) end |
#format_cart_gears(cart) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/rhc/output_helpers.rb', line 67 def format_cart_gears(cart) if cart.scalable? format_scaling_info(cart.scaling) elsif cart.shares_gears? "Located with #{cart.collocated_with.join(", ")}" else "%d %s" % [format_value(:current_scale, cart.current_scale), format_value(:gear_profile, cart.gear_profile)] end end |
#format_cart_header(cart) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/rhc/output_helpers.rb', line 55 def format_cart_header(cart) [ cart.name, cart.name != cart.display_name ? "(#{cart.display_name})" : nil, ].compact end |
#format_gear_info(info) ⇒ Object
77 78 79 80 |
# File 'lib/rhc/output_helpers.rb', line 77 def format_gear_info(info) "%d (defaults to %s)" % [:gear_count, :gear_profile].map{ |key| format_value(key, info[key]) } if info end |
#format_key_header(key) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/rhc/output_helpers.rb', line 122 def format_key_header(key) [ key.name, "(type: #{key.type})", ].compact end |
#format_scaling_info(scaling) ⇒ Object
62 63 64 65 |
# File 'lib/rhc/output_helpers.rb', line 62 def format_scaling_info(scaling) "x%d (minimum: %s, maximum: %s) on %s gears" % [:current_scale, :scales_from, :scales_to, :gear_profile].map{ |key| format_value(key, scaling[key]) } if scaling end |
#format_usage_message(cart) ⇒ Object
139 140 141 |
# File 'lib/rhc/output_helpers.rb', line 139 def (cart) "This gear costs an additional $#{cart.usage_rate} per gear after the first 3 gears." end |