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) ⇒ Runner
Returns a new instance of Runner.
7
8
9
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 7
def initialize(dir)
@dir = dir
end
|
Instance Method Details
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 11
def format!
logger.info @dir.color(:green)
exit_status = nil
Dir.chdir(@dir) do
skip_rename
begin
exit_status = terraform_fmt
ensure
restore_rename
end
end
exit_status
end
|
#restore_rename ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 48
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
38
39
40
41
42
43
44
45
46
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 38
def sh(command)
logger.debug("=> #{command}")
success = system(command)
unless success
logger.info "WARN: There were some errors running terraform fmt for files in #{@dir}:".color(:yellow)
logger.info "The errors are shown above"
end
$?.exitstatus
end
|
#skip_rename ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 26
def skip_rename
tf_files.each do |path|
if !skip?(path) && erb?(path)
FileUtils.mv(path, "#{path}.skip")
end
end
end
|
34
35
36
|
# File 'lib/terraspace/cli/fmt/runner.rb', line 34
def terraform_fmt
sh "#{Terraspace.terraform_bin} fmt"
end
|