Class: Pfm::Command::Destroy

Inherits:
Base
  • Object
show all
Defined in:
lib/iapi-idlc-sdk-pfm/command/destroy.rb

Instance Method Summary collapse

Methods inherited from Base

#build_base_dir, #build_dir, #build_exists?, #build_setup, #deploy_setup, #deploy_setupv2, #inf_base_dir, #needs_help?, #needs_version?, #run_with_default_options, #templates_dir, #verbose?

Methods included from Helpers

debug, err, msg, system_command

Constructor Details

#initializeDestroy

Returns a new instance of Destroy.



21
22
23
24
25
# File 'lib/iapi-idlc-sdk-pfm/command/destroy.rb', line 21

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

Instance Method Details

#destroy(dir) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/iapi-idlc-sdk-pfm/command/destroy.rb', line 52

def destroy(dir)
  Idlc::Deploy::Config.add_deployment_var('build', ENV['SERVER_BUILD'])
  Idlc::Deploy::Config.add_deployment_var('app_release', 'null')

  Terraform::Binary.destroy("#{dir}")
rescue
  raise DeploymentFailure, 'Finished with errors'
end

#params_valid?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/iapi-idlc-sdk-pfm/command/destroy.rb', line 72

def params_valid?
  @params_valid
end

#read_and_validate_paramsObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/iapi-idlc-sdk-pfm/command/destroy.rb', line 61

def read_and_validate_params
  arguments = parse_options(@params)

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

#run(params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/iapi-idlc-sdk-pfm/command/destroy.rb', line 27

def run(params)
  @params = params
  read_and_validate_params

  if params_valid?
    if (@config[:config_file])
      deploy_setupv2
      destroy(@config[:working_dir])
    else
      deploy_setup
      destroy(@workspace.tmp_dir)
    end
    # @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