Class: Airbrussh::CommandFormatter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Airbrussh::CommandFormatter
- 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
Instance Method Summary collapse
-
#exit_message ⇒ Object
Returns a green (success) or red (failure) message depending on the exit status.
-
#format_output(line) ⇒ Object
Prefixes the line with the command number and removes the newline.
-
#initialize(command, position) ⇒ CommandFormatter
constructor
A new instance of CommandFormatter.
-
#start_message ⇒ Object
Returns the abbreviated command (in yellow) with the number prefix.
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_message ⇒ Object
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 = if failure? red() else green() end << " #{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_message ⇒ Object
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 "#{number} #{yellow(abbreviated)}" end |