Class: Airbrussh::CommandFormatter

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Colors
Defined in:
lib/airbrussh/command_formatter.rb

Overview

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
    

Constant Summary

Constants included from Colors

Airbrussh::Colors::ANSI_CODES

Instance Method Summary collapse

Constructor Details

#initialize(command, position) ⇒ CommandFormatter

Returns a new instance of CommandFormatter.



17
18
19
20
# File 'lib/airbrussh/command_formatter.rb', line 17

def initialize(command, position)
  super(command)
  @position = position
end

Instance Method Details

#exit_messageObject

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”



44
45
46
47
48
49
50
51
# 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) ⇒ Object

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

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



26
27
28
# File 'lib/airbrussh/command_formatter.rb', line 26

def format_output(line)
  "#{number} #{line.chomp}"
end

#start_messageObject

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

start_message # => “01 echo hello”



34
35
36
# File 'lib/airbrussh/command_formatter.rb', line 34

def start_message
  "#{number} #{yellow(abbreviated)}"
end