<commit_before>module Terragov
  class Terraform
    def package_check(package)
      unless system("which #{package} >/dev/null")
        abort("Must install #{package}") unless HighLine.agree("Can't find #{package}. Install using Homebrew?")
        if system('which brew >/dev/null')
          system("brew install #{package}")
        else
          abort('Error: cannot find brew')
        end
      end
    end

    def execute(command, vars, backend, directory, dryrun = false, verbose = false)
      packages = %w[terraform sops]

      packages.each do |pkg|
        package_check(pkg)
      end

      if command == 'init'
        puts "Running 'init' is not required as it is applied for each command"
        exit 1
      end

      Dir.chdir directory
      init(backend, dryrun, verbose)

      full_command = "bash -c 'terraform #{command} #{vars}'"

      run(full_command, dryrun, verbose)
    end

    def init(backend_file, dryrun = false, verbose = false)
      init_cmd = "terraform init -backend-config #{backend_file}"
      run(init_cmd, dryrun, verbose)
    end

    def run(command, dryrun = false, verbose = false)
      if dryrun
        puts command
      else
        puts command if verbose
        abort("There was an issue running the command: #{command}") unless system(command)
      end
    end
  end
end<commit_msg>Add "detailed-exitcode" as default to plan<commit_after>module Terragov
  class Terraform
    def package_check(package)
      unless system("which #{package} >/dev/null")
        abort("Must install #{package}") unless HighLine.agree("Can't find #{package}. Install using Homebrew?")
        if system('which brew >/dev/null')
          system("brew install #{package}")
        else
          abort('Error: cannot find brew')
        end
      end
    end

    def execute(command, vars, backend, directory, dryrun = false, verbose = false)
      packages = %w[terraform sops]

      packages.each do |pkg|
        package_check(pkg)
      end

      if command == 'init'
        puts "Running 'init' is not required as it is applied for each command"
        exit 1
      end

      Dir.chdir directory
      init(backend, dryrun, verbose)

      if command == 'plan'
        command = 'plan -detailed-exitcode'
      end

      full_command = "bash -c 'terraform #{command} #{vars}'"

      run(full_command, dryrun, verbose)
    end

    def init(backend_file, dryrun = false, verbose = false)
      init_cmd = "terraform init -backend-config #{backend_file}"
      run(init_cmd, dryrun, verbose)
    end

    def run(command, dryrun = false, verbose = false)
      if dryrun
        puts command
      else
        puts command if verbose
        system(command)

        # Catch the output of "-detailed-exitcode"
        if $?.exitstatus == 2
          puts "Command completed successfully, but with updates available to apply"
          exit 2
        elsif $?.exitstatus != (0 or 2)
          abort("There was an issue running command: #{command}")
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09770491803278689, 'fraction_numerical': 0.0019672131147540984, 'mean_word_length': 2.3417305585980284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2455395', 'n_tokens_mistral': 885, 'n_tokens_neox': 866, 'n_words': 297}