diff --git a/lib/terraspace/cli/fmt.rb b/lib/terraspace/cli/fmt.rb index 6455e1f1..a4062ca6 100644 --- a/lib/terraspace/cli/fmt.rb +++ b/lib/terraspace/cli/fmt.rb @@ -3,8 +3,6 @@ class Fmt include Concerns::SourceDirs include Terraspace::Util::Logging - @@exit_status = 0 - def initialize(options={}) @options = options @mod_name = options[:mod] @@ -12,14 +10,11 @@ def initialize(options={}) def run logger.info "Formating terraform files" + exit_status = nil dirs.each do |dir| - err = format(dir) - if err - @@exit_status = 1 - end + exit_status = format(dir) end - - exit(@@exit_status) + exit(exit_status) end def format(dir) diff --git a/lib/terraspace/cli/fmt/runner.rb b/lib/terraspace/cli/fmt/runner.rb index 77a817d7..06c6f0db 100644 --- a/lib/terraspace/cli/fmt/runner.rb +++ b/lib/terraspace/cli/fmt/runner.rb @@ -10,18 +10,17 @@ def initialize(dir) def format! logger.info @dir.color(:green) - err = 0 + exit_status = nil Dir.chdir(@dir) do skip_rename begin - err = terraform_fmt + exit_status = terraform_fmt ensure restore_rename end end - - return err + exit_status end def skip_rename @@ -33,17 +32,17 @@ def skip_rename end def terraform_fmt - return sh "terraform fmt" + sh "terraform fmt" end def sh(command) logger.debug("=> #{command}") success = system(command) - return if success - - logger.info "WARN: There were some errors running terraform fmt for files in #{@dir}:".color(:yellow) - logger.info "The errors are shown above" - return 1 + 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 def restore_rename