Class: Hanami::CLI::InteractiveSystemCall Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/cli/interactive_system_call.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0

API:

  • private

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout, err: $stderr, exit_after: true) ⇒ InteractiveSystemCall

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of InteractiveSystemCall.

Since:

  • 2.1.0

API:

  • private



12
13
14
15
16
# File 'lib/hanami/cli/interactive_system_call.rb', line 12

def initialize(out: $stdout, err: $stderr, exit_after: true)
  @out = out
  @err = err
  @exit_after = exit_after
end

Instance Method Details

#call(cmd, *args, env: {}, out_prefix: "") ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0

API:

  • private



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hanami/cli/interactive_system_call.rb', line 20

def call(cmd, *args, env: {}, out_prefix: "")
  ::Bundler.with_original_env do
    threads = []
    exit_status = 0

    # rubocop:disable Lint/SuppressedException
    Open3.popen3(env, command(cmd, *args)) do |_stdin, stdout, stderr, wait_thr|
      threads << Thread.new do
        stdout.each_line do |line|
          out.puts("#{out_prefix}#{line}")
        end
      rescue IOError # FIXME: Check if this is legit
      end

      threads << Thread.new do
        stderr.each_line do |line|
          err.puts("#{out_prefix}#{line}")
        end
      rescue IOError # FIXME: Check if this is legit
      end

      threads.each(&:join)

      exit_status = wait_thr.value
    end
    # rubocop:enable Lint/SuppressedException

    exit(exit_status.exitstatus) if @exit_after
  end
end