Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal changes to restore compatibility with SSHKit master (log_command_* methods) #18

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ rvm:
- 2.1
- 2.2
env:
- sshkit="= 1.6.1"
- sshkit="= 1.7.1"
- sshkit="master"
# This is the old master before https://github.com/capistrano/sshkit/pull/257 was merged
- sshkit="ea211bcbbb71dab0152a18c2774922b7017e4edc"
- sshkit="= 1.7.1"
- sshkit="= 1.6.1"
before_install: gem install bundler --conservative --version '~> 1.8'
12 changes: 12 additions & 0 deletions lib/airbrussh/command_with_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Airbrussh
# Decorate a Command to give it the legacy stdout/stderr accessors.
class CommandWithData < SimpleDelegator
attr_accessor :stderr, :stdout

def initialize(command)
super
@stderr = ""
@stdout = ""
end
end
end
31 changes: 30 additions & 1 deletion lib/airbrussh/formatter.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# encoding: UTF-8
require "airbrussh/command_output"
require "airbrussh/command_with_data"
require "airbrussh/console"
require "colorize"
require "ostruct"
require "sshkit"

# rubocop:disable Metrics/ClassLength

module Airbrussh
class Formatter < SSHKit::Formatter::Abstract
class << self
Expand Down Expand Up @@ -78,14 +81,32 @@ def write_log_file_delimiter
end
end

def log_command_start(command)
@log_file_formatter.log_command_start(command)
disabling_log_file { write(Airbrussh::CommandWithData.new(command)) }
end

def log_command_data(command, stream_type, line)
@log_file_formatter.log_command_data(command, stream_type, line)

command_with_data = Airbrussh::CommandWithData.new(command)
command_with_data.public_send("#{stream_type}=", line)
disabling_log_file { write(command_with_data) }
end

def log_command_exit(command)
@log_file_formatter.log_command_exit(command)
disabling_log_file { write(Airbrussh::CommandWithData.new(command)) }
end

def write(obj)
# SSHKit's :pretty formatter mutates the stdout and stderr data in the
# command obj. So we need to dup it to ensure our copy is unscathed.
@log_file_formatter << obj.dup

case obj
when SSHKit::Command then write_command(obj)
when SSHKit::LogMessage then write_log_message(obj)
else write_command(obj)
end
end
alias_method :<<, :write
Expand Down Expand Up @@ -224,5 +245,13 @@ def clock
def config
Airbrussh.configuration
end

def disabling_log_file
orig_log_file_formatter = @log_file_formatter
@log_file_formatter = []
yield
ensure
@log_file_formatter = orig_log_file_formatter
end
end
end
Loading