class Reviewer::Guidance

Handles the logic around what to display after a command has been run

Attributes

command[R]
output[R]
result[R]

Public Class Methods

new(command:, result:, output: Reviewer.output) click to toggle source

Create an instance of guidance for suggesting recovery steps after errors @param command: [Command] the command that was run and needs recovery guidance @param result: [Result] the result of the command @param output: Reviewer.output [Output] the output channel for displaying content

@return [Guidance] the guidance class to suggest relevant recovery steps

# File lib/reviewer/guidance.rb, line 16
def initialize(command:, result:, output: Reviewer.output)
  @command = command
  @result = result
  @output = output
end

Public Instance Methods

show() click to toggle source

Prints the relevant guidance based on the command and result context

@return [void] prints the relevant guidance to the stream

# File lib/reviewer/guidance.rb, line 25
def show
  case result
  when executable_not_found? then show_missing_executable_guidance
  when cannot_execute?       then show_unrecoverable_guidance
  else                            show_syntax_guidance
  end
end

Private Instance Methods

cannot_execute?() click to toggle source

Conditional check for when the command result was that it was unable to be executed

@return [Boolean] true if the result indicates the command couldn't be executed

# File lib/reviewer/guidance.rb, line 45
def cannot_execute?
  ->(result) { result.cannot_execute? }
end
executable_not_found?() click to toggle source

Conditional check for when the command result was that the executable couldn't be found

@return [Boolean] true if the result indicates the command couldn't be found

# File lib/reviewer/guidance.rb, line 38
def executable_not_found?
  ->(result) { result.executable_not_found? }
end
show_missing_executable_guidance() click to toggle source

Shows the recovery guidance for when a command is missing

@return [void] prints missing executable guidance

# File lib/reviewer/guidance.rb, line 52
def show_missing_executable_guidance
  output.missing_executable_guidance(command)
end
show_syntax_guidance() click to toggle source

Shows suggestions for ignoring or disable rules when a command fails after reviewing code

@return [void] prints syntax guidance

# File lib/reviewer/guidance.rb, line 66
def show_syntax_guidance
  output.syntax_guidance(
    ignore_link: command.tool.links[:ignore_syntax],
    disable_link: command.tool.links[:disable_syntax]
  )
end
show_unrecoverable_guidance() click to toggle source

Shows the recovery guidance for when a command generates an unrecoverable error

@return [void] prints unrecoverable error guidance

# File lib/reviewer/guidance.rb, line 59
def show_unrecoverable_guidance
  output.unrecoverable(result.stderr)
end