Class: Reviewer::Runner::Strategies::Captured

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/runner/strategies/captured.rb

Overview

Execution strategy for a runner to run a command quietly by capturing the output and only displaying it if there's a failure that justifies it

Constant Summary collapse

PROGRESS_GRAY =

256-color ANSI codes for progress bar styling (not in AnsiStyles' 16-color palette)

"\e[38;5;245m"
PROGRESS_DARK_GRAY =
"\e[38;5;240m"
ANSI_RESET =
"\e[0m"
ERASE_LINE =
"\r\e[2K"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ self

Create an instance of the captured strategy for a command runner so that any output is fully suppressed so as to not create too much noise when running multiple commands.

Parameters:

  • runner (Runner)

    the instance of the runner to apply the strategy to



26
27
28
29
# File 'lib/reviewer/runner/strategies/captured.rb', line 26

def initialize(runner)
  @runner = runner
  @start_time = Time.now
end

Instance Attribute Details

#runnerRunner (readonly)

the instance of the runner that will be executed with this strategy

Returns:

  • (Runner)

    the current value of runner



12
13
14
# File 'lib/reviewer/runner/strategies/captured.rb', line 12

def runner
  @runner
end

#start_timeTime (readonly)

the start time for the strategy_for timing purposes

Returns:

  • (Time)

    the current value of start_time



12
13
14
# File 'lib/reviewer/runner/strategies/captured.rb', line 12

def start_time
  @start_time
end

Instance Method Details

#preparevoid

This method returns an undefined value.

The prepare command strategy when running a command and capturing the results



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/reviewer/runner/strategies/captured.rb', line 34

def prepare
  command = runner.prepare_command

  display_progress(command) { runner.shell.capture_prep(command) }

  # Erase the prep progress bar — the run step will show its own
  stream.print(ERASE_LINE) if style_enabled? && runner.streaming?

  # Running the prepare command, so make sure the timestamp is updated
  runner.update_last_prepared_at
end

#runvoid

This method returns an undefined value.

The run command strategy when running a command and capturing the results



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/reviewer/runner/strategies/captured.rb', line 49

def run
  command = runner.command

  display_progress(command) { runner.shell.capture_main(command) }

  # Skip output for non-streaming modes - results are formatted at the end
  return unless runner.streaming?

  # Missing tools are handled by the Runner (shows "Skipped (not installed)")
  return if runner.shell.result.executable_not_found?

  # If it's successful, show that it was a success and how long it took to run, otherwise,
  # it wasn't successful and we got some explaining to do...
  runner.success? ? show_timing_result : show_command_output
end