vmc-ng/lib/vmc/cli/app.rb in vmc-0.4.0.beta.50 vs vmc-ng/lib/vmc/cli/app.rb in vmc-0.4.0.beta.51

- old
+ new

@@ -39,10 +39,12 @@ :from_given => by_name("space") input :name, :desc => "Filter by name regexp" input :runtime, :desc => "Filter by runtime regexp" input :framework, :desc => "Filter by framework regexp" input :url, :desc => "Filter by url regexp" + input :one_line, :alias => "-l", :type => :boolean, :default => false, + :desc => "One line per app; tabular format" def apps if space = input[:space] || client.current_space apps = with_progress("Getting applications in #{c(space.name, :name)}") do # depth of 2 for service binding instance names @@ -65,12 +67,36 @@ apps.reject! do |a| !app_matches(a, input) end - spaced(apps.sort_by(&:name)) do |a| - display_app(a) + apps = apps.sort_by(&:name) + + if input[:one_line] + rows = apps.collect { |a| + [ c(a.name, :name), + app_status(a), + "#{human_mb(a.memory)} x #{a.total_instances}", + v2? && (a.production ? "prod" : "dev"), + a.runtime.name, + a.url + ] + } + + tabular( + [ b("name"), + b("status"), + b("usage"), + v2? && b("plan"), + b("runtime"), + b("url") + ], + *rows) + else + spaced(apps) do |a| + display_app(a) + end end end desc "Show app information" @@ -320,11 +346,11 @@ ask("Instances", :default => default) } input(:memory, :desc => "Memory limit") { |default| ask("Memory Limit", :choices => memory_choices(default), :allow_other => true, - :default => human_size(default * 1024 * 1024, 0)) + :default => human_mb(default)) } input :plan, :default => "D100", :desc => "Application plan (e.g. D100, P200)" input :restart, :type => :boolean, :default => true, :desc => "Restart app after updating?" @@ -519,15 +545,18 @@ end stats = info[:stats] usage = stats[:usage] line "instance #{c("\##{idx}", :instance)}:" - indented do - line "cpu: #{percentage(usage[:cpu])} of #{b(stats[:cores])} cores" - line "memory: #{usage(usage[:mem] * 1024, stats[:mem_quota])}" - line "disk: #{usage(usage[:disk], stats[:disk_quota])}" + if usage + line "cpu: #{percentage(usage[:cpu])} of #{b(stats[:cores])} cores" + line "memory: #{usage(usage[:mem] * 1024, stats[:mem_quota])}" + line "disk: #{usage(usage[:disk], stats[:disk_quota])}" + else + line c("stats unavailable (not running?)", :bad) + end end end end @@ -745,11 +774,11 @@ line "#{c(a.name, :name)}: #{status}" indented do line "platform: #{b(a.framework.name)} on #{b(a.runtime.name)}" - start_line "usage: #{b(human_size(a.memory * 1024 * 1024, 0))}" + start_line "usage: #{b(human_mb(a.memory))}" print " #{d(IS_UTF8 ? "\xc3\x97" : "x")} #{b(a.total_instances)}" print " instance#{a.total_instances == 1 ? "" : "s"}" line @@ -1106,10 +1135,14 @@ end format("%.#{precision}fB", num) end + def human_mb(num) + human_size(num * 1024 * 1024, 0) + end + def target_base client.target.sub(/^https?:\/\/([^\.]+\.)?(.+)\/?/, '\2') end def memory_choices(exclude = 0) @@ -1119,10 +1152,10 @@ available = limit - used + exclude mem = 64 choices = [] until mem > available - choices << human_size(mem * 1024 * 1024, precision = 0) + choices << human_mb(mem) mem *= 2 end choices end