Class: TerraformDevKit::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/TerraformDevKit/command.rb

Class Method Summary collapse

Class Method Details

.process_output(stream, print_output) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/TerraformDevKit/command.rb', line 16

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

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

.run(cmd, directory: Dir.pwd, print_output: true) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/TerraformDevKit/command.rb', line 5

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