Sha256: 02432e113a3ce74b2eabfdce89e8e697f139f3a57a0f74d4e761ec435b2ea1f5

Contents?: true

Size: 1.95 KB

Versions: 8

Compression:

Stored size: 1.95 KB

Contents

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

module Pfm
  module Command
    class Plan < Base
      banner 'Usage: pfm plan [options]'

      option :app_release,
             short:        '-a VERSION',
             long:         '--app-release VERSION',
             description:  'Application Version Number to Deploy',
             default:      ''

      option :server_build,
             short:        '-b NUMBER',
             long:         '--server-build NUMBER',
             description:  'Server Build Number to Deploy',
             default:      ENV['SERVER_BUILD']

      option :landscape,
             short:        '-l',
             long:         '--landscape',
             description:  'Format the output with the terraform_landscape gem',
             boolean:      true,
             default:      false

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

      def run(params)
        @params = params
        read_and_validate_params

        if params_valid?
          deploy_setup
          plan
          # @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 plan
        begin
          Terraform::Binary.plan(@workspace.tmp_dir) unless @config[:landscape]
          Terraform::Binary.plan("#{@workspace.tmp_dir} | landscape") if @config[:landscape]
        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

8 entries across 8 versions & 1 rubygems

Version Path
idlc-sdk-pfm-1.0.0.rc12 lib/idlc-sdk-pfm/command/plan.rb
idlc-sdk-pfm-1.0.0.rc11 lib/idlc-sdk-pfm/command/plan.rb
idlc-sdk-pfm-1.0.0.rc10 lib/idlc-sdk-pfm/command/plan.rb
idlc-sdk-pfm-1.0.0.rc9 lib/idlc-sdk-pfm/command/plan.rb
idlc-sdk-pfm-1.0.0.rc8 lib/idlc-sdk-pfm/command/plan.rb
idlc-sdk-pfm-1.0.0.rc7 lib/idlc-sdk-pfm/command/plan.rb
idlc-sdk-pfm-1.0.0.rc6 lib/idlc-sdk-pfm/command/plan.rb
idlc-sdk-pfm-1.0.0.rc5 lib/idlc-sdk-pfm/command/plan.rb