Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup terraspace fmt exit status return #313

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/terraspace/cli/fmt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ class Fmt
include Concerns::SourceDirs
include Terraspace::Util::Logging

@@exit_status = 0

def initialize(options={})
@options = options
@mod_name = options[:mod]
end

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)
tongueroo marked this conversation as resolved.
Show resolved Hide resolved
end

exit(@@exit_status)
exit(exit_status)
end

def format(dir)
Expand Down
19 changes: 9 additions & 10 deletions lib/terraspace/cli/fmt/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down