From b0233395163d61aacd5463bc7ff623720afbd85b Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 6 Dec 2016 11:21:21 -0800 Subject: [PATCH] Move pretty status printing to Utils namespace and out of commands --- lib/vmfloaty.rb | 20 ++------------------ lib/vmfloaty/utils.rb | 21 +++++++++++++++++++++ lib/vmfloaty/version.rb | 2 +- vmfloaty.gemspec | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 4590d8a..2c20963 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -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 diff --git a/lib/vmfloaty/utils.rb b/lib/vmfloaty/utils.rb index dd63a74..e4263c1 100644 --- a/lib/vmfloaty/utils.rb +++ b/lib/vmfloaty/utils.rb @@ -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 diff --git a/lib/vmfloaty/version.rb b/lib/vmfloaty/version.rb index 9016754..cb6925e 100644 --- a/lib/vmfloaty/version.rb +++ b/lib/vmfloaty/version.rb @@ -1,6 +1,6 @@ class Version - @version = '0.7.4' + @version = '0.7.5' def self.get @version diff --git a/vmfloaty.gemspec b/vmfloaty.gemspec index 543614e..95354ce 100644 --- a/vmfloaty.gemspec +++ b/vmfloaty.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'vmfloaty' - s.version = '0.7.4' + s.version = '0.7.5' s.authors = ['Brian Cain'] s.email = ['brian.cain@puppetlabs.com'] s.license = 'Apache'