lib/heirloom/cli/formatter/catalog.rb in heirloom-0.12.1 vs lib/heirloom/cli/formatter/catalog.rb in heirloom-0.12.2
- old
+ new
@@ -1,43 +1,57 @@
module Heirloom
module CLI
module Formatter
class Catalog
- def format(args)
+
+ def initialize(args)
@catalog = args[:catalog]
+ end
+
+ def detailed_format(args)
@name = args[:name]
+ @region = args[:region]
- return summary unless @name
-
- return "Heirloom #{@name} not found in catalog." unless name_exists?
-
filter_by_name
details
+ end
+
+ def summary_format(args)
+ @region = args[:region]
+
+ summary
end
private
- def name_exists?
- @catalog.include? @name
+ def remove_heirloom_prefix
+ Hash[@catalog.sort.map { |k, v| [k.sub(/heirloom_/, ''), v] }]
end
+ def add_indent_prefix
+ Hash[remove_heirloom_prefix.sort.map { |k, v| [k.sub(/^/, ' '), v] }]
+ end
+
def filter_by_name
- @catalog.select! {|k| @name == k }
+ @catalog.select! {|k| "heirloom_#{@name}" == k }
end
def summary
- @catalog.keys.join "\n"
+ s = @region + "\n"
+ s << add_indent_prefix.keys.join("\n")
end
def details
+ @catalog = remove_heirloom_prefix
data = @catalog.each_pair.map do |k,v|
- urls = v["regions"].map do |region|
+ urls = v["regions"].sort.map do |region|
bucket_prefix = v["bucket_prefix"].first
" #{region}-s3-url : s3://#{bucket_prefix}-#{region}/#{k}"
end
d = k + "\n"
- d << " regions : " + @catalog[k]["regions"].join(", ") + "\n"
+ d << " metadata_region : #{@region}\n"
+ d << " regions : " + @catalog[k]["regions"].sort.join(", ") + "\n"
d << " bucket_prefix : " + @catalog[k]["bucket_prefix"].first + "\n"
d << urls.join("\n")
end
data.join "\n"
end