Sha256: f2475d6e933776cc6d6787e02a4b7fb797b7f6d6a571377e2d7a94c6552c68ad

Contents?: true

Size: 631 Bytes

Versions: 8

Compression:

Stored size: 631 Bytes

Contents

require 'open3'

module TerraformDevKit
  class Command
    def self.run(cmd, directory: Dir.pwd, print_output: true)
      Open3.popen2e(cmd, chdir: directory) do |_, stdout_and_stderr, thread|
        output = process_output(stdout_and_stderr, print_output)

        thread.join
        raise "Error running command #{cmd}" unless thread.value.success?
        return output
      end
    end

    private_class_method
    def self.process_output(stream, print_output)
      lines = []

      until (line = stream.gets).nil?
        print line if print_output
        lines << line.strip
      end
      lines
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
TerraformDevKit-0.3.4 lib/TerraformDevKit/command.rb
TerraformDevKit-0.3.3 lib/TerraformDevKit/command.rb
TerraformDevKit-0.3.2 lib/TerraformDevKit/command.rb
TerraformDevKit-0.3.1 lib/TerraformDevKit/command.rb
TerraformDevKit-0.3.1.pre.rc1 lib/TerraformDevKit/command.rb
TerraformDevKit-0.2.7 lib/TerraformDevKit/command.rb
TerraformDevKit-0.2.6 lib/TerraformDevKit/command.rb
TerraformDevKit-0.2.5 lib/TerraformDevKit/command.rb