Class: SSHKit::Formatter::Pretty

Inherits:
Abstract
  • Object
show all
Defined in:
lib/sshkit/formatters/pretty.rb

Instance Attribute Summary

Attributes inherited from Abstract

#original_output

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from SSHKit::Formatter::Abstract

Instance Method Details

#write(obj) ⇒ Object Also known as: <<



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
# File 'lib/sshkit/formatters/pretty.rb', line 9

def write(obj)
  if obj.is_a? SSHKit::Command

    return if obj.verbosity < SSHKit.config.output_verbosity

    unless obj.started?
      original_output << level(obj.verbosity) + uuid(obj) + "Running #{c.yellow(c.bold(String(obj)))} on #{c.blue(obj.host.to_s)}\n"
      if SSHKit.config.output_verbosity == Logger::DEBUG
        original_output << level(Logger::DEBUG) + uuid(obj) + c.white("Command: #{c.blue(obj.to_command)}") + "\n"
      end
    end

    if SSHKit.config.output_verbosity == Logger::DEBUG
      if obj.complete? && !obj.stdout.empty?
        obj.stdout.lines.each do |line|
          original_output << level(Logger::DEBUG) + uuid(obj) + c.green("\t" + line)
        end
      end

      if obj.complete? && !obj.stderr.empty?
        obj.stderr.lines.each do |line|
          original_output << level(Logger::DEBUG) + uuid(obj) + c.red("\t" + line)
        end
      end
    end

    if obj.finished?
      original_output << level(obj.verbosity) + uuid(obj) + "Finished in #{sprintf('%5.3f seconds', obj.runtime)} command #{c.bold { obj.failure? ? c.red('failed') : c.green('successful') }}.\n"
    end

  else
    original_output << c.black(c.on_yellow("Output formatter doesn't know how to handle #{obj.inspect}\n"))
  end
end