Class: Terraspace::CLI::Fmt::Runner
Constant Summary
collapse
- SKIP_PATTERN =
/\.skip$/
Instance Method Summary
collapse
#logger
#app_source_dirs, #source_dirs
Constructor Details
#initialize(dir, options) ⇒ Runner
Returns a new instance of Runner.
6
7
8
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 6
def initialize(dir, options)
@dir, @options = dir, options
end
|
Instance Method Details
#args ⇒ Object
37
38
39
40
41
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 37
def args
mod = nil pass = Terraspace::Terraform::Args::Pass.new(mod, "fmt", @options)
pass.args.flatten.join(' ')
end
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 10
def format!
logger.info @dir.color(:green)
exit_status = nil
Dir.chdir(@dir) do
rename_to_skip_fmt
begin
exit_status = terraform_fmt
ensure
restore_rename
end
end
exit_status
end
|
#rename_to_skip_fmt ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 25
def rename_to_skip_fmt
tf_files.each do |path|
if !skip?(path) && erb?(path)
FileUtils.mv(path, "#{path}.skip")
end
end
end
|
#restore_rename ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 57
def restore_rename
tf_files.each do |path|
if skip?(path) && erb?(path)
FileUtils.mv(path, path.sub(SKIP_PATTERN, '')) end
end
end
|
#sh(command) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 43
def sh(command)
logger.debug("=> #{command}")
system(command)
case $?.exitstatus
when 2 logger.info "WARN: There were some errors running #{Terraspace.terraform_bin} fmt for files in #{@dir}:".color(:yellow)
logger.info "The errors are shown above"
when 3 logger.debug "fmt ran and changes were made unless -check or -write=false"
end
$?.exitstatus
end
|
33
34
35
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 33
def terraform_fmt
sh "#{Terraspace.terraform_bin} fmt #{args}"
end
|