From e725a63119686746a2cf2dd84ba5cfb9d7314c1a Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Wed, 21 Jan 2015 15:36:07 +0000 Subject: [PATCH 1/2] MCO-558 make `mco facts` handle no results Here we check that the facts data structure contains values before attempting to present them. --- plugins/mcollective/application/facts.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/mcollective/application/facts.rb b/plugins/mcollective/application/facts.rb index 791c2f51..58da78c7 100644 --- a/plugins/mcollective/application/facts.rb +++ b/plugins/mcollective/application/facts.rb @@ -45,7 +45,11 @@ def main end end - show_single_fact_report(configuration[:fact], facts, options[:verbose]) + if facts.empty? + puts "No values found for fact #{configuration[:fact]}\n" + else + show_single_fact_report(configuration[:fact], facts, options[:verbose]) + end printrpcstats From 5c9615f12ebd9289e88e44d8109ab166ab0efc50 Mon Sep 17 00:00:00 2001 From: Richard Clamp Date: Wed, 21 Jan 2015 15:39:17 +0000 Subject: [PATCH 2/2] (maint) refactor ternary statement for clarity Here we rewrite a ternary statement as a more verbose if/else/end block to make the assignment that is happening in the branches more visible. --- plugins/mcollective/application/facts.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/mcollective/application/facts.rb b/plugins/mcollective/application/facts.rb index 58da78c7..a1e9c7d8 100644 --- a/plugins/mcollective/application/facts.rb +++ b/plugins/mcollective/application/facts.rb @@ -38,7 +38,11 @@ def main begin value = resp[:body][:data][:value] if value - facts.include?(value) ? facts[value] << resp[:senderid] : facts[value] = [ resp[:senderid] ] + if facts.include?(value) + facts[value] << resp[:senderid] + else + facts[value] = [ resp[:senderid] ] + end end rescue Exception => e STDERR.puts "Could not parse facts for #{resp[:senderid]}: #{e.class}: #{e}"