1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# frozen_string_literal: true
require 'aruba/processes/spawn_process'
# Aruba
module Aruba
# Processes
module Processes
# Run your command in `system()` to make debugging it easier. This will
# make the process use the default input and output streams so the
# developer can interact with it directly. This means that part of Aruba's
# functionality is disabled. I.e., checks for output, and passing input
# programmatically will not work.
#
# `DebugProcess` is not meant for direct use - `DebugProcess.new` - by
# users. Only its public methods are part of the public API of aruba, e.g.
# `#stdin`, `#stdout`.
#
# @private
class DebugProcess < BasicProcess
# Use only if mode is :debug
def self.match?(mode)
mode == :debug || (mode.is_a?(Class) && mode <= DebugProcess)
end
def start
@started = true
Dir.chdir @working_directory do
Aruba.platform.with_replaced_environment(environment) do
@exit_status = system(command, *arguments) ? 0 : 1
end
end
end
# Return stdin
#
# @return [NilClass]
# Nothing
def stdin(*); end
# Return stdout
#
# @return [String]
# A predefined string to make users aware they are using the DebugProcess
def stdout(*)
'This is the debug launcher on STDOUT. ' \
'If this output is unexpected, please check your setup.'
end
# Return stderr
#
# @return [String]
# A predefined string to make users aware they are using the DebugProcess
def stderr(*)
'This is the debug launcher on STDERR. ' \
'If this output is unexpected, please check your setup.'
end
# Write to nothing
def write(*); end
# Close nothing
def close_io(*); end
# Stop process
def stop(*)
@started = false
@exit_status
end
# Terminate process
def terminate(*)
stop
end
def interactive?
true
end
end
end
end
|