Module: Pangea::Shell

Defined in:
lib/pangea-orchestrator/shell.rb

Class Method Summary collapse

Class Method Details

.run(command) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pangea-orchestrator/shell.rb', line 5

def run(command)
  Open3.popen3(command) do |_stdin, stdout, stderr, wait_thr|
    # Process standard output
    stdout.each_line do |line|
      parsed = JSON.parse(line.strip)
      puts JSON.pretty_generate(parsed)
      puts "\n---\n" # Separator between JSON objects
    rescue JSON::ParserError
      warn "⚠️  Invalid JSON received: #{line.inspect}"
    end

    # Handle standard error
    unless (err = stderr.read).empty?
      warn "\n❌ Command errors:\n#{err}"
    end

    exit_status = wait_thr.value
    warn "\n🔥 Command failed with status #{exit_status.exitstatus}" unless exit_status.success?
  end
end