class Airbrussh::CommandFormatter

Decorates an SSHKit Command to add string output helpers and the command's position within currently executing rake task:

Public Class Methods

new(command, position) click to toggle source
Calls superclass method
# File lib/airbrussh/command_formatter.rb, line 17
def initialize(command, position)
  super(command)
  @position = position
end

Public Instance Methods

exit_message() click to toggle source

Returns a green (success) or red (failure) message depending on the exit status.

exit_message # => “✔ 01 user@host 0.084s” exit_message # => “✘ 01 user@host 0.084s”

# File lib/airbrussh/command_formatter.rb, line 44
def exit_message
  message = if failure?
              red(failure_message)
            else
              green(success_message)
            end
  message << " #{runtime}"
end
format_output(line) click to toggle source

Prefixes the line with the command number and removes the newline.

format_output(“hellon”) # => “01 hello”

# File lib/airbrussh/command_formatter.rb, line 26
def format_output(line)
  "#{number} #{line.chomp}"
end
start_message() click to toggle source

Returns the abbreviated command (in yellow) with the number prefix.

start_message # => “01 echo hello”

# File lib/airbrussh/command_formatter.rb, line 34
def start_message
  "#{number} #{yellow(abbreviated)}"
end

Private Instance Methods

abbreviated() click to toggle source
# File lib/airbrussh/command_formatter.rb, line 65
def abbreviated
  to_s.sub(%r{^/usr/bin/env }, "")
end
failure_message() click to toggle source
# File lib/airbrussh/command_formatter.rb, line 77
def failure_message
  "✘ #{number} #{user_at_host}"
end
number() click to toggle source
# File lib/airbrussh/command_formatter.rb, line 69
def number
  format("%02d", @position.to_i + 1)
end
runtime() click to toggle source
Calls superclass method
# File lib/airbrussh/command_formatter.rb, line 61
def runtime
  format("%5.3fs", super)
end
success_message() click to toggle source
# File lib/airbrussh/command_formatter.rb, line 73
def success_message
  "✔ #{number} #{user_at_host}"
end
user_at_host() click to toggle source
# File lib/airbrussh/command_formatter.rb, line 55
def user_at_host
  user_str = host.user || (host.ssh_options || {})[:user]
  host_str = host.hostname
  [user_str, host_str].compact.join("@")
end