-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from robd/no-colors-for-non-tty-outputs
No colors for non tty outputs
- Loading branch information
Showing
17 changed files
with
289 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
module SSHKit | ||
module Backend | ||
|
||
# Printer is used to implement --dry-run in Capistrano | ||
class Printer < Abstract | ||
|
||
def execute_command(cmd) | ||
output << cmd | ||
end | ||
|
||
alias :upload! :execute | ||
alias :download! :execute | ||
alias :test :execute | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,18 @@ | ||
require 'colorize' | ||
|
||
module Color | ||
String.colors.each do |color| | ||
instance_eval <<-RUBY, __FILE__, __LINE__ | ||
def #{color}(string = '') | ||
string = yield if block_given? | ||
colorize? ? string.colorize(:color => :#{color}) : string | ||
end | ||
RUBY | ||
end | ||
module SSHKit | ||
class Color | ||
def initialize(output, env=ENV) | ||
@output, @env = output, env | ||
end | ||
|
||
String.modes.each do |mode| | ||
instance_eval <<-RUBY, __FILE__, __LINE__ | ||
def #{mode}(string = '') | ||
string = yield if block_given? | ||
colorize? ? string.colorize(:mode => :#{mode}) : string | ||
end | ||
RUBY | ||
end | ||
def colorize(obj, color, mode=nil) | ||
string = obj.to_s | ||
colorize? ? string.colorize(color: color, mode: mode) : string | ||
end | ||
|
||
class << self | ||
def colorize? | ||
ENV['SSHKIT_COLOR'] || $stdout.tty? | ||
@env['SSHKIT_COLOR'] || (@output.respond_to?(:tty?) && @output.tty?) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ module Backend | |
class TestConnectionPool < UnitTest | ||
|
||
def setup | ||
super | ||
pool.flush_connections | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'helper' | ||
|
||
module SSHKit | ||
module Backend | ||
class TestPrinter < UnitTest | ||
|
||
def setup | ||
super | ||
SSHKit.config.output = SSHKit::Formatter::Pretty.new(output) | ||
SSHKit.config.output_verbosity = Logger::DEBUG | ||
Command.any_instance.stubs(:uuid).returns('aaaaaa') | ||
end | ||
|
||
def output | ||
@output ||= String.new | ||
end | ||
|
||
def printer | ||
@printer ||= Printer.new(Host.new('example.com')) | ||
end | ||
|
||
def test_execute | ||
printer.execute 'uname -a' | ||
assert_output_lines( | ||
' INFO [aaaaaa] Running /usr/bin/env uname -a on example.com', | ||
' DEBUG [aaaaaa] Command: uname -a' | ||
) | ||
end | ||
|
||
def test_test_method | ||
printer.test '[ -d /some/file ]' | ||
|
||
assert_output_lines( | ||
' DEBUG [aaaaaa] Running /usr/bin/env [ -d /some/file ] on example.com', | ||
' DEBUG [aaaaaa] Command: [ -d /some/file ]' | ||
) | ||
end | ||
|
||
def test_capture | ||
result = printer.capture 'ls -l' | ||
|
||
assert_equal '', result | ||
|
||
assert_output_lines( | ||
' DEBUG [aaaaaa] Running /usr/bin/env ls -l on example.com', | ||
' DEBUG [aaaaaa] Command: ls -l' | ||
) | ||
end | ||
|
||
def test_upload | ||
printer.upload! '/some/file', '/remote' | ||
assert_output_lines( | ||
' INFO [aaaaaa] Running /usr/bin/env /some/file /remote on example.com', | ||
' DEBUG [aaaaaa] Command: /usr/bin/env /some/file /remote' | ||
) | ||
end | ||
|
||
def test_download | ||
printer.download! 'remote/file', '/local/path' | ||
assert_output_lines( | ||
' INFO [aaaaaa] Running /usr/bin/env remote/file /local/path on example.com', | ||
' DEBUG [aaaaaa] Command: /usr/bin/env remote/file /local/path' | ||
) | ||
end | ||
|
||
private | ||
|
||
def assert_output_lines(*expected_lines) | ||
assert_equal(expected_lines, output.split("\n")) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.