lib/kpm/formatter.rb in kpm-0.4.1 vs lib/kpm/formatter.rb in kpm-0.4.2
- old
+ new
@@ -60,28 +60,31 @@
"[#{sha[0..5]}..]"
end
end
- def format(all_plugins)
- if all_plugins.size == 0
+ def format(data, labels = nil)
+ if data.nil? || data.size == 0
return
end
- # What we want to output
- labels = [{:label => :plugin_name},
- {:label => :plugin_key},
- {:label => :type},
- {:label => :group_id},
- {:label => :artifact_id},
- {:label => :packaging},
- {:label => :versions, :formatter => VersionFormatter.name}]
+ if labels.nil?
+ # What we want to output
+ labels = [{:label => :plugin_name},
+ {:label => :plugin_key},
+ {:label => :type},
+ {:label => :group_id},
+ {:label => :artifact_id},
+ {:label => :packaging},
+ {:label => :versions, :formatter => VersionFormatter.name}]
+ end
+
# Compute label to print along with max size for each label
labels_format_argument = []
- all_plugins.keys.each do |key|
- v = all_plugins[key]
+ data.keys.each do |key|
+ v = data[key]
labels.each do |e|
# sanitize entry at the same time
v[e[:label]] = v[e[:label]] || "???"
formatter = e[:formatter].nil? ? DefaultFormatter.new(e[:label], v[e[:label]]) : e[:formatter].to_class.new(e[:label], v[e[:label]])
@@ -104,11 +107,11 @@
puts "\n#{border}\n"
puts "#{format}\n" % labels_format_argument
puts "#{border}\n"
- all_plugins.keys.each do |key|
- v = all_plugins[key]
+ data.keys.each do |key|
+ v = data[key]
arguments = []
labels.inject(arguments) do |res, e|
formatter = e[:formatter].nil? ? DefaultFormatter.new(e[:label], v[e[:label]]) : e[:formatter].to_class.new(e[:label], v[e[:label]])
res << formatter.to_s