Module: MuxTf::Cli::PlanSummary

Extended by:
TerraformHelpers, PiotrbCliUtils::ShellHelpers, PiotrbCliUtils::Util
Defined in:
lib/mux_tf/cli/plan_summary.rb

Class Method Summary collapse

Methods included from TerraformHelpers

tf_apply, tf_force_unlock, tf_init, tf_plan, tf_show, tf_validate

Class Method Details

.run(args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mux_tf/cli/plan_summary.rb', line 12

def run(args)
  options = {
    interactive: false,
    hierarchy: false
  }

  args = OptionParser.new { |opts|
    opts.on("-i") do |v|
      options[:interactive] = v
    end
    opts.on("-h") do |v|
      options[:hierarchy] = v
    end
  }.parse!(args)

  raise "must specify plan file in interactive mode" if options[:interactive] && args[0].blank?

  plan = if args[0]
           PlanSummaryHandler.from_file(args[0])
         else
           PlanSummaryHandler.from_data(JSON.parse($stdin.read))
         end

  if options[:interactive]
    abort_message = catch(:abort) { plan.run_interactive }
    log pastel.red("Aborted: #{abort_message}") if abort_message
  else
    if options[:hierarchy]
      plan.nested_summary.each do |line|
        puts line
      end
    else
      plan.flat_summary.each do |line|
        puts line
      end
      plan.output_summary.each do |line|
        puts line
      end
    end
    puts
    puts plan.summary
  end
end