Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updates to reflect latest working theories

  • Loading branch information...
commit e1f61b24e2b237515a22c815f906b9478a88084f 1 parent 192d2b1
@geemus authored
View
54 lib/ext/heroku/command/apps.rb
@@ -9,20 +9,16 @@ class Heroku::Command::Apps < Heroku::Command::Base
# list your apps
#
def index
- style_info("apps")
+ style_header("#{heroku.user} Apps")
list = heroku.list
if list.size > 0
- apps_by_owner = Hash.new {|hash,key| hash[key] = []}
- list.map do |name, owner|
- if owner == heroku.user
- apps_by_owner["owned by me"] << name
- else
- apps_by_owner["shared with me"] << name
- end
- end
- style_object(apps_by_owner)
+ owned, shared = list.partition {|app, owner| owner == heroku.user}
+ style_info("Owned by Me")
+ style_object(owned.map {|app, owner| app})
+ style_info("Shared with Me")
+ style_object(shared.map {|app, owner| app})
else
- hputs(" You have no apps.")
+ hputs("You have no apps.")
end
end
@@ -36,7 +32,7 @@ def index
#
def info
unless options[:raw]
- style_info("#{app} info")
+ style_header("#{app} Info")
end
attrs = heroku.info(app)
@@ -54,35 +50,35 @@ def info
end
else
data = {
- 'addons' => !attrs[:addons].empty? && attrs[:addons].map {|addon| addon['description']},
- 'create status' => (attrs[:create_status] != 'complete') && attrs[:create_status],
- 'cron finished at' => attrs[:cron_finished_at] && format_date(attrs[:cron_finished_at]),
- 'cron next run' => attrs[:cron_next_run] && format_date(attrs[:cron_next_run]),
- 'database size' => attrs[:database_size] && format_bytes(attrs[:database_size]),
- 'domain name' => attrs[:domain_name],
- 'dynos' => (attrs[:stack] != 'cedar') && attrs[:dynos],
- 'git url' => attrs[:git_url],
- 'owner' => attrs[:owner],
- 'repo size' => attrs[:repo_size] && format_bytes(attrs[:repo_size]),
- 'slug size' => attrs[:slug_size] && format_bytes(attrs[:slug_size]),
- 'stack' => attrs[:stack],
- 'web url' => attrs[:web_url],
- 'workers' => (attrs[:stack] != 'cedar') && attrs[:workers],
+ 'Addons' => !attrs[:addons].empty? && attrs[:addons].map {|addon| addon['description']},
+ 'Create Status' => (attrs[:create_status] != 'complete') && attrs[:create_status],
+ 'Cron Finished At' => attrs[:cron_finished_at] && format_date(attrs[:cron_finished_at]),
+ 'Cron Next Run' => attrs[:cron_next_run] && format_date(attrs[:cron_next_run]),
+ 'Database Size' => attrs[:database_size] && format_bytes(attrs[:database_size]),
+ 'Domain Name' => attrs[:domain_name],
+ 'Dynos' => (attrs[:stack] != 'cedar') && attrs[:dynos],
+ 'Git URL' => attrs[:git_url],
+ 'Owner' => attrs[:owner],
+ 'Repo Size' => attrs[:repo_size] && format_bytes(attrs[:repo_size]),
+ 'Slug Size' => attrs[:slug_size] && format_bytes(attrs[:slug_size]),
+ 'Stack' => attrs[:stack],
+ 'Web URL' => attrs[:web_url],
+ 'Workers' => (attrs[:stack] != 'cedar') && attrs[:workers],
}
data.reject! {|key,value| !value}
collaborators = attrs[:collaborators].delete_if { |c| c[:email] == attrs[:owner] }
unless collaborators.empty?
attrs[:collaborators].reject! {|collaborator| collaborator[:email] == attrs[:owner]}
- data['collaborators'] = attrs[:collaborators].map {|collaborator| collaborator[:email]}
+ data['Collaborators'] = attrs[:collaborators].map {|collaborator| collaborator[:email]}
end
if attrs[:database_tables]
- data['database size'].gsub!('(empty)', '0K') + " in #{quantify("table", attrs[:database_tables])}"
+ data['Database Size'].gsub!('(empty)', '0K') + " in #{quantify("table", attrs[:database_tables])}"
end
if attrs[:dyno_hours].is_a?(Hash)
- data['dyno hours'] = attrs[:dyno_hours].keys.map do |type|
+ data['Dyno Hours'] = attrs[:dyno_hours].keys.map do |type|
" = %s: %0.2f dyno-hours" % [ type.to_s.capitalize, attrs[:dyno_hours][type] ]
end
end
View
21 lib/ext/heroku/command/ps.rb
@@ -57,15 +57,28 @@ def workers
# list processes for an app
#
def index
- style_info("#{app} processes by command")
+ style_header("#{app} Processes")
ps = heroku.ps(app)
if ps.length > 0
- data = Hash.new {|hash,key| hash[key] = {}}
+ named_processes = Hash.new {|hash,key| hash[key] = []}
+ other_processes = []
ps.each do |p|
- data["`#{p['command']}`"][p['process']] = "#{p['state']} for #{time_ago(p['elapsed']).gsub(/ ago/, "")}"
+ type = p["process"].split(".",2).first
+ if type == "run"
+ other_processes << %|#{p["process"]}: `#{p["command"]}`, #{p["state"]} for #{time_ago(p["elapsed"]).gsub(/ ago/, "")}|
+ else
+ named_processes[%|#{type}: `#{p["command"]}`|] << %|#{p["process"]}: #{p["state"]} for #{time_ago(p["elapsed"]).gsub(/ ago/, "")}|
+ end
+ end
+ named_processes.keys.sort.each do |key|
+ style_info(key)
+ style_object(named_processes[key])
+ end
+ unless other_processes.empty?
+ style_info("Other Processes")
+ style_object(other_processes)
end
- style_object(data)
else
hputs(" You have no processes.")
end
View
36 lib/ext/heroku/helpers.rb
@@ -2,41 +2,51 @@ module Heroku
module Helpers
def style_warning(message)
- hputs(" ~ #{message}")
+ hputs("~~~ #{message}")
end
def style_action(action)
- hprint("* #{action} ")
+ hprint("=== #{action}")
+ end
+
+ def style_header(header)
+ hputs
+ style_info(header)
+ hputs
end
def style_info(info)
- hputs("+ #{info}: ")
+ hputs("=== #{info}")
end
def style_object(object)
case object
when Array
object.sort.each do |item|
- hputs(" - #{item}")
+ hputs("#{item}")
end
+ hputs
when Hash
- object.keys.sort_by {|key| key.to_s}.each do |key|
- hprint(" = #{key}: ")
+ key_length = object.keys.map {|key| key.length}.max + 2
+ sorted_keys = object.keys.sort_by {|key| key.to_s}
+ sorted_keys.each do |key|
+ hprint("#{key}: ".ljust(key_length))
case data = object[key]
when Array
- hputs
- data.sort.each do |item|
- hputs(" - #{item}")
+ data.sort.each_with_index do |item, index|
+ unless index == 0
+ hprint(" " * key_length)
+ end
+ hputs(item)
end
- when Hash
hputs
- data.keys.sort_by {|key| key.to_s}.each do |key|
- hputs(" = #{key}: #{data[key]}")
- end
else
hputs("#{data}")
end
end
+ unless object[sorted_keys.last].is_a?(Array)
+ hputs
+ end
else
hputs(object.to_s)
end
Please sign in to comment.
Something went wrong with that request. Please try again.