Forward standard error stream from remote execution
This commit is contained in:
@@ -2,7 +2,7 @@ module Producer
|
||||
module Core
|
||||
class Action
|
||||
extend Forwardable
|
||||
def_delegators :@env, :input, :output, :remote
|
||||
def_delegators :@env, :input, :output, :error_output, :remote
|
||||
def_delegators :remote, :fs
|
||||
|
||||
attr_reader :env, :arguments
|
||||
|
@@ -7,7 +7,7 @@ module Producer
|
||||
end
|
||||
|
||||
def apply
|
||||
remote.execute(arguments.first, output)
|
||||
remote.execute(arguments.first, output, error_output)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -31,7 +31,7 @@ module Producer
|
||||
@arguments = args
|
||||
@stdin = stdin
|
||||
@stdout = stdout
|
||||
@env = Env.new(input: stdin, output: stdout)
|
||||
@env = Env.new(input: stdin, output: stdout, error_output: stderr)
|
||||
end
|
||||
|
||||
def parse_arguments!
|
||||
|
@@ -1,15 +1,16 @@
|
||||
module Producer
|
||||
module Core
|
||||
class Env
|
||||
attr_reader :input, :output, :registry, :logger
|
||||
attr_reader :input, :output, :error_output, :registry, :logger
|
||||
attr_accessor :target, :verbose, :dry_run
|
||||
|
||||
def initialize(input: $stdin, output: $stdout, remote: nil, registry: {})
|
||||
@verbose = @dry_run = false
|
||||
@input = input
|
||||
@output = output
|
||||
@remote = remote
|
||||
@registry = registry
|
||||
def initialize(input: $stdin, output: $stdout, error_output: $stderr, remote: nil, registry: {})
|
||||
@verbose = @dry_run = false
|
||||
@input = input
|
||||
@output = output
|
||||
@error_output = error_output
|
||||
@remote = remote
|
||||
@registry = registry
|
||||
end
|
||||
|
||||
def remote
|
||||
|
@@ -24,13 +24,17 @@ module Producer
|
||||
@fs ||= Remote::FS.new(session.sftp.connect)
|
||||
end
|
||||
|
||||
def execute(command, output = '')
|
||||
def execute(command, output = '', error_output = '')
|
||||
channel = session.open_channel do |channel|
|
||||
channel.exec command do |ch, success|
|
||||
ch.on_data do |c, data|
|
||||
output << data
|
||||
end
|
||||
|
||||
ch.on_extended_data do |c, type, data|
|
||||
error_output << data
|
||||
end
|
||||
|
||||
ch.on_request 'exit-status' do |c, data|
|
||||
exit_status = data.read_long
|
||||
fail RemoteCommandExecutionError, command if exit_status != 0
|
||||
|
@@ -6,13 +6,18 @@ module Producer
|
||||
fail 'no session for mock remote!'
|
||||
end
|
||||
|
||||
def execute(command, output = '')
|
||||
tokens = command.split
|
||||
def execute(command, output = '', error_output = '')
|
||||
tokens = command.gsub(/\d?>.*/, '').split
|
||||
program = tokens.shift
|
||||
|
||||
case program
|
||||
when 'echo'
|
||||
output << tokens.join(' ') << "\n"
|
||||
out = tokens.join(' ') << "\n"
|
||||
if command =~ />&2\z/
|
||||
error_output << out
|
||||
else
|
||||
output << out
|
||||
end
|
||||
when 'true'
|
||||
output << ''
|
||||
when 'false'
|
||||
|
Reference in New Issue
Block a user