diff --git a/lib/fog/core/ssh.rb b/lib/fog/core/ssh.rb index efe431239..e88cd5eb6 100644 --- a/lib/fog/core/ssh.rb +++ b/lib/fog/core/ssh.rb @@ -42,6 +42,7 @@ module Fog @address = address @username = username + @debug = options.delete :debug @options = { :paranoid => false }.merge(options) end @@ -51,7 +52,7 @@ module Fog begin Net::SSH.start(@address, @username, @options) do |ssh| commands.each do |command| - result = Result.new(command) + result = Result.new(command, @debug) ssh.open_channel do |ssh_channel| ssh_channel.request_pty ssh_channel.exec(command) do |channel, success| @@ -91,6 +92,15 @@ module Fog end + require 'delegate' + + class DebugString < SimpleDelegator + def <<(add_me) + puts add_me + super + end + end + class Result attr_accessor :command, :stderr, :stdout, :status @@ -108,10 +118,10 @@ module Fog Formatador.display_line(stderr.split("\r\n")) end - def initialize(command) + def initialize(command, debug=false) @command = command - @stderr = '' - @stdout = '' + @stderr = debug ? DebugString.new('') : '' + @stdout = debug ? DebugString.new('') : '' end end