Class: Pfm::Command::Format

Inherits:
Base
  • Object
show all
Defined in:
lib/idlc-sdk-pfm/command/format.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

#initializeFormat

Returns a new instance of Format.



9
10
11
12
13
# File 'lib/idlc-sdk-pfm/command/format.rb', line 9

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

Instance Method Details

#fmtObject

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/idlc-sdk-pfm/command/format.rb', line 34

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

#params_valid?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/idlc-sdk-pfm/command/format.rb', line 59

def params_valid?
  @params_valid
end

#read_and_validate_paramsObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/idlc-sdk-pfm/command/format.rb', line 48

def read_and_validate_params
  arguments = parse_options(@params)

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

#run(params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/idlc-sdk-pfm/command/format.rb', line 15

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