Sha256: 70c8096f6ce586fc6b3ff1874f0bd641dbeef38dcec6a91494accd90e82849d6

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module MuxTf
  module Cli
    module PlanSummary
      extend PiotrbCliUtils::Util
      extend PiotrbCliUtils::ShellHelpers
      extend TerraformHelpers

      class << self
        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 Paint["Aborted: #{abort_message}", :red] 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
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mux_tf-0.13.0 lib/mux_tf/cli/plan_summary.rb
mux_tf-0.12.0 lib/mux_tf/cli/plan_summary.rb
mux_tf-0.11.0 lib/mux_tf/cli/plan_summary.rb
mux_tf-0.10.0 lib/mux_tf/cli/plan_summary.rb
mux_tf-0.9.0 lib/mux_tf/cli/plan_summary.rb