class Airbrussh::CommandFormatter
Decorates an SSHKit Command to add string output helpers and the command's position within currently executing rake task:
-
position - zero-based position of this command in the list of
all commands that have been run in the current rake task; in some cases this could be nil
Public Class Methods
new(command, position)
click to toggle source
Calls superclass method
# File lib/airbrussh/command_formatter.rb, line 15 def initialize(command, position) super(command) @position = position end
Public Instance Methods
exit_message(log_file=nil)
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”
If `log_file` is specified, it is appended to the message in the failure case.
#exit_message(“out.log”) # => “✘ 01 user@host (see out.log for details) 0.084s”
# File lib/airbrussh/command_formatter.rb, line 48 def exit_message(log_file=nil) message = if failure? red(failure_message(log_file)) else green(success_message) end message << " #{gray(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 24 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 32 def start_message "#{number} #{yellow(abbreviated)}" end
Private Instance Methods
abbreviated()
click to toggle source
# File lib/airbrussh/command_formatter.rb, line 69 def abbreviated to_s.sub(%r{^/usr/bin/env }, "") end
failure_message(log_file)
click to toggle source
# File lib/airbrussh/command_formatter.rb, line 81 def failure_message(log_file) message = "✘ #{number} #{user_at_host}" message << " (see #{log_file} for details)" if log_file message end
number()
click to toggle source
# File lib/airbrussh/command_formatter.rb, line 73 def number format("%02d", @position.to_i + 1) end
runtime()
click to toggle source
Calls superclass method
# File lib/airbrussh/command_formatter.rb, line 65 def runtime format("%5.3fs", super) end
success_message()
click to toggle source
# File lib/airbrussh/command_formatter.rb, line 77 def success_message "✔ #{number} #{user_at_host}" end
user_at_host()
click to toggle source
# File lib/airbrussh/command_formatter.rb, line 59 def user_at_host user_str = host.user || (host.ssh_options || {})[:user] host_str = host.hostname [user_str, host_str].compact.join("@") end