Move pretty status printing to Utils namespace and out of commands

This commit is contained in:
Brian Cain 2016-12-06 11:21:21 -08:00
parent 5f0ace0c82
commit b023339516
4 changed files with 25 additions and 20 deletions

View file

@ -427,24 +427,7 @@ class Vmfloaty
if options.json
pp status
else
pools.select! {|name,pool| pool['ready'] < pool['max']} if ! verbose
width = pools.keys.map(&:length).max
pools.each do |name,pool|
begin
max = pool['max']
ready = pool['ready']
pending = pool['pending']
missing = max - ready - pending
char = 'o'
puts "#{name.ljust(width)} #{(char*ready).green}#{(char*pending).yellow}#{(char*missing).red}"
rescue => e
puts "#{name.ljust(width)} #{e.red}"
end
end
puts
puts message.colorize(status['status']['ok'] ? :default : :red)
Utils.prettyprint_status(status, message, pools, verbose)
end
exit status['status']['ok']
@ -464,6 +447,7 @@ class Vmfloaty
summary = Pooler.summary(verbose, url)
pp summary
exit 0
end
end

View file

@ -92,4 +92,25 @@ class Utils
running_vms = vms['running']
running_vms
end
def self.prettyprint_status(status, message, pools, verbose)
pools.select! {|name,pool| pool['ready'] < pool['max']} if ! verbose
width = pools.keys.map(&:length).max
pools.each do |name,pool|
begin
max = pool['max']
ready = pool['ready']
pending = pool['pending']
missing = max - ready - pending
char = 'o'
puts "#{name.ljust(width)} #{(char*ready).green}#{(char*pending).yellow}#{(char*missing).red}"
rescue => e
puts "#{name.ljust(width)} #{e.red}"
end
end
puts
puts message.colorize(status['status']['ok'] ? :default : :red)
end
end

View file

@ -1,6 +1,6 @@
class Version
@version = '0.7.4'
@version = '0.7.5'
def self.get
@version