Class: Reviewer::Runner::Formatter

Inherits:
Object
  • Object
show all
Includes:
Output::Formatting
Defined in:
lib/reviewer/runner/formatter.rb

Overview

Display logic for tool execution: tool identity, success, failure, skipped, guidance

Constant Summary

Constants included from Output::Formatting

Output::Formatting::CHECKMARK, Output::Formatting::XMARK

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Formatter

Creates a formatter for runner-specific display

Parameters:

  • output (Output)

    the console output handler



18
19
20
21
# File 'lib/reviewer/runner/formatter.rb', line 18

def initialize(output)
  @output = output
  @printer = output.printer
end

Instance Method Details

#current_command(command) ⇒ void

This method returns an undefined value.

Displays the exact command string being executed for debugging and copy/paste

Parameters:

  • command (Command, String)

    the command to display



36
37
38
39
40
# File 'lib/reviewer/runner/formatter.rb', line 36

def current_command(command)
  printer.print(:default, '')
  printer.puts(:muted, String(command))
  output.newline
end

#failure(details, command: nil) ⇒ void

This method returns an undefined value.

Displays a failure message with details and optionally the failed command

Parameters:

  • details (String)

    the failure summary (e.g. exit status)

  • command (Command, String, nil) (defaults to: nil)

    the command that failed, if applicable



69
70
71
72
73
74
75
76
77
78
# File 'lib/reviewer/runner/formatter.rb', line 69

def failure(details, command: nil)
  printer.print(:failure, 'Failure')
  printer.puts(:muted, " #{details}")

  return unless command

  output.newline
  printer.puts(:bold, 'Failed Command:')
  printer.puts(:muted, String(command))
end

#guidance(summary, details) ⇒ void

This method returns an undefined value.

Displays contextual guidance after a failure to help the user recover

Parameters:

  • summary (String)

    the guidance heading

  • details (String, nil)

    the guidance body (skipped if nil)



94
95
96
97
98
99
100
# File 'lib/reviewer/runner/formatter.rb', line 94

def guidance(summary, details)
  return unless details

  output.newline
  printer.puts(:bold, summary)
  printer.puts(:muted, details)
end

#skipped(reason = 'no matching files') ⇒ void

This method returns an undefined value.

Displays a skip notice with the reason

Parameters:

  • reason (String) (defaults to: 'no matching files')

    why the tool was skipped



58
59
60
61
62
# File 'lib/reviewer/runner/formatter.rb', line 58

def skipped(reason = 'no matching files')
  printer.print(:muted, 'Skipped')
  printer.puts(:muted, " (#{reason})")
  output.newline
end

#success(timer) ⇒ void

This method returns an undefined value.

Displays a success message with timing breakdown

Parameters:

  • timer (Shell::Timer)

    the timer with prep and main execution times



46
47
48
49
50
51
52
# File 'lib/reviewer/runner/formatter.rb', line 46

def success(timer)
  printer.print(:success, 'Success')
  printer.print(:success_light, " #{timer.total_seconds}s")
  printer.print(:warning_light, " (#{timer.prep_percent}% prep ~#{timer.prep_seconds}s)") if timer.prepped?
  output.newline
  output.newline
end

#tool_summary(tool) ⇒ void

This method returns an undefined value.

Prints the tool name and description as a header before execution

Parameters:

  • tool (Tool)

    the tool being run



27
28
29
30
# File 'lib/reviewer/runner/formatter.rb', line 27

def tool_summary(tool)
  printer.print(:bold, tool.name)
  printer.puts(:muted, " #{tool.description}")
end

#unrecoverable(details) ⇒ void

This method returns an undefined value.

Displays an unrecoverable error that prevents further execution

Parameters:

  • details (String)

    the error description



84
85
86
87
# File 'lib/reviewer/runner/formatter.rb', line 84

def unrecoverable(details)
  printer.puts(:error, 'Unrecoverable Error:')
  printer.puts(:muted, details)
end