lib/compare_task.rb in machinery-tool-1.6.0 vs lib/compare_task.rb in machinery-tool-1.7.0

- old
+ new

@@ -15,12 +15,39 @@ # To contact SUSE about this file by physical or electronic mail, # you may find current contact information at www.suse.com class CompareTask def compare(description1, description2, scopes, options = {}) - output = render_comparison(description1, description2, scopes, options) + if options[:show_html] + render_html_comparison(description1, description2, scopes, options) + else + output = render_comparison(description1, description2, scopes, options) - Machinery::Ui.puts output + Machinery::Ui.puts output + end + end + + def render_html_comparison(description1, description2, scopes, options) + diff = { + meta: { + description_a: description1.name, + description_b: description2.name, + } + } + + scopes.each do |scope| + if description1[scope] && description2[scope] + comparison = description1[scope].compare_with(description2[scope]) + diff[scope] = comparison.map { |scope| scope.as_json if scope } + end + end + + target = "/tmp/machinery-html-comparison" + FileUtils.rm_r(target) if Dir.exists?(target) + FileUtils.mkdir_p(target) + + Html.generate_comparison(diff, target) + LoggedCheetah.run("xdg-open", File.join(target, "index.html")) end def render_comparison(description1, description2, scopes, options = {}) output = "" identical = true