lib/sfn/command/diff.rb in sfn-3.0.28 vs lib/sfn/command/diff.rb in sfn-3.0.30

- old
+ new

@@ -4,11 +4,10 @@ module Sfn class Command # Diff command class Diff < Command - include Sfn::CommandModule::Base include Sfn::CommandModule::Template include Sfn::CommandModule::Stack # Diff the stack with existing stack @@ -20,11 +19,11 @@ stack = provider.stack(name) rescue Miasma::Error::ApiError::RequestError stack = nil end - if(stack) + if stack config[:print_only] = true file = load_template_file file = parameter_scrub!(file.dump) ui.info "#{ui.color('SparkleFormation:', :bold)} #{ui.color('diff', :blue)} - #{name}" @@ -36,37 +35,36 @@ raise "Failed to locate stack: #{name}" end end # @todo needs updates for better provider compat - def diff_stack(stack, file, parent_names=[]) + def diff_stack(stack, file, parent_names = []) stack_template = stack.template nested_stacks = Hash[ file.fetch('Resources', file.fetch('resources', {})).find_all do |name, value| value.fetch('Properties', {})['Stack'] end ] nested_stacks.each do |name, value| n_stack = stack.nested_stacks(false).detect do |ns| ns.data[:logical_id] == name end - if(n_stack) + if n_stack diff_stack(n_stack, value['Properties']['Stack'], [*parent_names, stack.data.fetch(:logical_id, stack.name)].compact) end file['Resources'][name]['Properties'].delete('Stack') end ui.info "#{ui.color('Stack diff:', :bold)} #{ui.color((parent_names + [stack.data.fetch(:logical_id, stack.name)]).compact.join(' > '), :blue)}" stack_diff = HashDiff.diff(stack.template, file) - if(config[:raw_diff]) + if config[:raw_diff] ui.info "Dumping raw template diff:" require 'pp' pp stack_diff else - added_resources = stack_diff.find_all do |item| item.first == '+' && item[1].match(/Resources\.[^.]+$/) end removed_resources = stack_diff.find_all do |item| item.first == '-' && item[1].match(/Resources\.[^.]+$/) @@ -75,37 +73,36 @@ item[1].start_with?('Resources.') && !item[1].end_with?('TemplateURL') && !item[1].include?('Properties.Parameters') end - added_resources - removed_resources - if(added_resources.empty? && removed_resources.empty? && modified_resources.empty?) + if added_resources.empty? && removed_resources.empty? && modified_resources.empty? ui.info 'No changes detected' ui.puts else - - unless(added_resources.empty?) + unless added_resources.empty? ui.info ui.color('Added Resources:', :green, :bold) added_resources.each do |item| ui.print ui.color(" -> #{item[1].split('.').last}", :green) ui.puts " [#{item[2]['Type']}]" end ui.puts end - unless(modified_resources.empty?) + unless modified_resources.empty? ui.info ui.color('Modified Resources:', :yellow, :bold) m_resources = Hash.new.tap do |hash| modified_resources.each do |item| _, key, path = item[1].split('.', 3) hash[key] ||= {} prefix, a_key = path.split('.', 2) hash[key][prefix] ||= [] matched = hash[key][prefix].detect do |i| i[:path] == a_key end - if(matched) - if(item.first == '-') + if matched + if item.first == '-' matched[:original] = item[2] else matched[:new] = item[2] end else @@ -135,33 +132,29 @@ end end ui.puts end - unless(removed_resources.empty?) + unless removed_resources.empty? ui.info ui.color('Removed Resources:', :red, :bold) removed_resources.each do |item| ui.print ui.color(" <- #{item[1].split('.').last}", :red) ui.puts " [#{item[2]['Type']}]" end ui.puts end run_callbacks_for(:after_stack_diff, - :diff => stack_diff, - :diff_info => { - :added => added_resources, - :modified => modified_resources, - :removed => removed_resources - }, - :api_stack => stack, - :new_template => file - ) + :diff => stack_diff, + :diff_info => { + :added => added_resources, + :modified => modified_resources, + :removed => removed_resources, + }, + :api_stack => stack, + :new_template => file) end - end - end - end end end