Class: CleoQualityReview::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/cleo_quality_review/command_runner.rb

Overview

Executes shell commands and captures output

Instance Method Summary collapse

Instance Method Details

#run(*command, env: {}, stdin_data: nil) ⇒ CommandResult

Run a shell command and capture its output

Parameters:

  • command (Array<String>)

    command and arguments to execute

  • env (Hash{String => String}) (defaults to: {})

    environment variables

  • stdin_data (String, nil) (defaults to: nil)

    data to pipe to stdin

Returns:



17
18
19
20
21
22
23
24
25
# File 'lib/cleo_quality_review/command_runner.rb', line 17

def run(*command, env: {}, stdin_data: nil)
  stdout, stderr, status = if stdin_data.nil?
    Open3.capture3(env, *command)
  else
    Open3.capture3(env, *command, stdin_data: stdin_data)
  end

  CommandResult.new(stdout: stdout, stderr: stderr, status: status)
end