Class: Hanami::CLI::InteractiveSystemCall Private
- Inherits:
-
Object
- Object
- Hanami::CLI::InteractiveSystemCall
- 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.
Instance Method Summary collapse
- #call(cmd, *args, env: {}, out_prefix: "") ⇒ Object private
-
#initialize(out: $stdout, err: $stderr, exit_after: true) ⇒ InteractiveSystemCall
constructor
private
A new instance of InteractiveSystemCall.
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.
12 13 14 15 16 17 |
# 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 super() 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.
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 50 |
# File 'lib/hanami/cli/interactive_system_call.rb', line 21 def call(cmd, *args, env: {}, out_prefix: "") ::Bundler.with_unbundled_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 |