Sha256: cb5111f8c665c5bc4d7469a0004d80b9f9482e89b75ddf4f4f465334a614bccd

Contents?: true

Size: 1.41 KB

Versions: 47

Compression:

Stored size: 1.41 KB

Contents

require 'idlc-sdk-pfm/command/base'
require 'mixlib/shellout'

module Pfm
  module Command
    class Format < Base
      banner 'Usage: pfm format [options]'

      def initialize
        super
        @params_valid = true
        @errors = []
      end

      def run(params)
        @params = params
        read_and_validate_params

        if params_valid?
          fmt
          # @workspace.cleanup causing bundler issues
          0
        else
          @errors.each { |error| err("Error: #{error}") }
          parse_options(params)
          msg(opt_parser)
          1
        end
      rescue DeploymentFailure => e
        err("ERROR: #{e.message}\n")
        1
      end

      def fmt
        raise InvalidRepository, 'This doesn\'t look like a valid infrastructure repository' unless File.directory? "#{inf_base_dir}/tf"
        tf_paths = %W[#{inf_base_dir}/tf lib/tf/modules]

        begin
          tf_paths.each do |path|
            # Format the file to a canonical syntax
            Terraform::Binary.fmt(path)
          end
        rescue
          raise DeploymentFailure, 'Finished with errors'
        end
      end

      def read_and_validate_params
        arguments = parse_options(@params)

        case arguments.size
        when 0
          @params_valid = true
        else
          @params_valid = false
        end
      end

      def params_valid?
        @params_valid
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
idlc-sdk-pfm-1.2.2 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.2.1 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.2.0 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.1.4 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.1.3 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.1.2 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.1.1 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.1.0 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.21 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.20 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.19 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.18 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.17 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.16 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.15 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.14 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.13 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.12 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.11 lib/idlc-sdk-pfm/command/format.rb
idlc-sdk-pfm-1.0.10 lib/idlc-sdk-pfm/command/format.rb